Magento Module-Manager Bash Completion

The following bash_completion script will enable your Linux shell to auto-complete Magento modman commands.  Make sure you have modman in your $PATH, then simply copy the file to /etc/bash_completion.d/modman or append to ~/.bash_completion.

  1. #!/bin/bash
  2. _modman()
  3. {
  4. local cur prev opts modules mm
  5. COMPREPLY=()
  6. cur="${COMP_WORDS[COMP_CWORD]}"
  7. prev="${COMP_WORDS[COMP_CWORD-1]}"
  8.  
  9. opts="init --help --version"
  10. mm=$(_modman_get_mm)
  11. module=$(_modman_get_module)
  12.  
  13. if [ -n "$mm" ] ; then
  14. opts="${opts} list repair update-all"
  15. modules=$(modman list)
  16. fi
  17.  
  18. case "${prev}" in
  19. modman)
  20. opts="${opts} ${modules}"
  21. [ -n "$module" ] && opts="${opts} update deploy"
  22. ;;
  23.  
  24. init | --help | --version | list | repair | update-all)
  25. opts=""
  26. modules=""
  27. ;;
  28.  
  29. deploy | update | checkout | clone)
  30. opts="--force --copy"
  31. modules=""
  32. ;;
  33.  
  34. --force | --copy)
  35. opts=""
  36. modules=""
  37. ;;
  38.  
  39. *)
  40. [ ! -d "$mm/${prev}" ] && opts="checkout clone"
  41. [ -d "$mm/${prev}" ] && opts="update deploy"
  42. modules=""
  43. ;;
  44.  
  45. esac
  46.  
  47. COMPREPLY=( $(compgen -W "${opts} ${modules}" -- ${cur}) )
  48. return 0
  49. }
  50.  
  51. _modman_get_mm()
  52. {
  53. local root _pwd
  54. _pwd=`pwd`
  55. root=$(_modman_realpath `pwd`)
  56. while ! [ -d $root/.modman ]; do
  57. if [ "$root" = "/" ]; then
  58. cd $_pwd && return 1
  59. fi
  60. cd ..
  61. root=`pwd`
  62. done
  63. cd $_pwd
  64. echo "$root/.modman"
  65. }
  66.  
  67. _modman_get_module()
  68. {
  69. local root module modpath mm _pwd
  70. _pwd=`pwd`
  71. mm=$(_modman_get_mm)
  72. root="$(dirname $mm)"
  73. module=''
  74. while [ "$root" != "$(pwd)" ]; do
  75. modpath=`pwd`
  76. if [ "$mm" = "$(dirname $modpath)" ]; then
  77. module=$(basename $modpath)
  78. break
  79. fi
  80. cd ..
  81. done
  82. cd $_pwd
  83.  
  84. if [ -z "$module" ] ; then
  85. return 1
  86. fi
  87.  
  88. echo $module
  89. }
  90.  
  91. _modman_realpath()
  92. {
  93. fname=${1%/} # strips trailing '/'
  94. while [ -L "$fname" ]; do
  95. oldfname="$fname"
  96. fname="$(command ls -l $fname)"
  97. fname="${fname#*> }"
  98. if [ "$fname" = . ] ; then
  99. fname="$(dirname $oldfname)"
  100. elif echo $fname | grep -vq '^/' - ; then
  101. fname="$(dirname $oldfname)/$fname"
  102. fi
  103. done
  104. pushd $(dirname $fname) > /dev/null
  105. fname=$(pwd -P)/$(basename $fname)
  106. popd > /dev/null
  107. echo $fname
  108. }
  109.  
  110. complete -F _modman modman

Tags:

Leave a Reply