{"id":32,"date":"2007-11-18T01:45:50","date_gmt":"2007-11-18T00:45:50","guid":{"rendered":"http:\/\/schuerig.de\/michael\/blog\/index.php\/2007\/11\/18\/script-generate-bash-completion\/"},"modified":"2021-11-24T09:20:32","modified_gmt":"2021-11-24T08:20:32","slug":"script-generate-bash-completion","status":"publish","type":"post","link":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2007\/11\/18\/script-generate-bash-completion\/","title":{"rendered":"Bash completion for script\/generate"},"content":{"rendered":"<p>The Rails generator <tt>script\/generate<\/tt> knows pretty well what things it can generate. In fact, it knows much better than I do. So, I think it could really give me some help when I&#8217;m typing along on the command line.<\/p>\n<p>If you save the snippet below as <tt>\/etc\/bash_completion.d\/generate<\/tt> you can enjoy this help, too.<\/p>\n<p><code><\/p>\n<pre>\r\n_generate()\r\n{\r\n  local cur\r\n\r\n  COMPREPLY=()\r\n  cur=${COMP_WORDS[COMP_CWORD]}\r\n\r\n  if [ ! -d \"$PWD\/script\" ]; then\r\n    return 0\r\n  fi\r\n\r\n  if [ $COMP_CWORD == 1 ] && [[ \"$cur\" == -* ]]; then\r\n    COMPREPLY=( $( compgen -W '-h -v\\\\\r\n      --help --version'\\\\\r\n      -- $cur ))\r\n    return 0\r\n  fi\r\n\r\n  if [ $COMP_CWORD == 2 ] && [[ \"$cur\" == -* ]]; then\r\n    COMPREPLY=( $( compgen -W '-p -f -s -q -t -c\\\\\r\n      --pretend --force --skip --quiet --backtrace --svn'\\\\\r\n      -- $cur ))\r\n    return 0\r\n  fi\r\n\r\n  COMPREPLY=( $(script\/generate --help | \\\\\r\n    awk -F ': ' '\/^  (Plugins|Rubygems|Builtin|User):\/ { gsub(\/, *\/, \"\\n\", $2); print $2 }' | \\\\\r\n    command grep \"^$cur\" \\\\\r\n  ))\r\n}\r\n\r\ncomplete -F _generate $default generate\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Rails generator script\/generate knows pretty well what things it can generate. In fact, it knows much better than I do. So, I think it could really give me some help when I&#8217;m typing along on the command line. If &hellip; <a href=\"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2007\/11\/18\/script-generate-bash-completion\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-rails","category-shell"],"_links":{"self":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":1,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/32\/revisions\/125"}],"wp:attachment":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}