virtualm

set_linux_bash

May 5th, 2020
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 94.51 KB | None | 0 0
  1. BASH=/bin/bash
  2. BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:histappend:interactive_comments:progcomp:promptvars:sourcepath
  3. BASH_ALIASES=()
  4. BASH_ARGC=([0]="0")
  5. BASH_ARGV=()
  6. BASH_CMDS=()
  7. BASH_COMPLETION_VERSINFO=([0]="2" [1]="8")
  8. BASH_LINENO=()
  9. BASH_SOURCE=()
  10. BASH_VERSINFO=([0]="5" [1]="0" [2]="3" [3]="1" [4]="release" [5]="arm-unknown-linux-gnueabihf")
  11. BASH_VERSION='5.0.3(1)-release'
  12. COLORTERM=truecolor
  13. COLUMNS=80
  14. DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  15. DESKTOP_SESSION=LXDE-pi
  16. DIRSTACK=()
  17. DISPLAY=:0.0
  18. EUID=1000
  19. GDMSESSION=lightdm-xsession
  20. GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
  21. GROUPS=()
  22. HISTCONTROL=ignoreboth
  23. HISTFILE=/home/pi/.bash_history
  24. HISTFILESIZE=2000
  25. HISTSIZE=1000
  26. HOME=/home/pi
  27. HOSTNAME=raspberrypi
  28. HOSTTYPE=arm
  29. IFS=$' \t\n'
  30. LANG=hu_HU.UTF-8
  31. LANGUAGE=hu_HU.UTF-8
  32. LC_ALL=hu_HU.UTF-8
  33. LINES=24
  34. LOGNAME=pi
  35. LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
  36. MACHTYPE=arm-unknown-linux-gnueabihf
  37. MAILCHECK=60
  38. NO_AT_BRIDGE=1
  39. OPTERR=1
  40. OPTIND=1
  41. OSTYPE=linux-gnueabihf
  42. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
  43. PIPESTATUS=([0]="0")
  44. PPID=3625
  45. PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] '
  46. PS2='> '
  47. PS4='+ '
  48. PWD=/home/pi
  49. QT_QPA_PLATFORMTHEME=qt5ct
  50. RC=0
  51. SAL_USE_VCLPLUGIN=gtk3
  52. SHELL=/bin/bash
  53. SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
  54. SHLVL=1
  55. SSH_AGENT_PID=666
  56. SSH_AUTH_SOCK=/tmp/ssh-eGvJdWEfuX9g/agent.583
  57. TERM=xterm-256color
  58. TEXTDOMAIN=Linux-PAM
  59. UID=1000
  60. USER=pi
  61. VIRTUALENVWRAPPER_ENV_BIN_DIR=bin
  62. VIRTUALENVWRAPPER_HOOK_DIR=/home/pi/.virtualenvs
  63. VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
  64. VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
  65. VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
  66. VIRTUALENVWRAPPER_VIRTUALENV=virtualenv
  67. VIRTUALENVWRAPPER_VIRTUALENV_CLONE=virtualenv-clone
  68. VIRTUALENVWRAPPER_WORKON_CD=1
  69. VTE_VERSION=5402
  70. WORKON_HOME=/home/pi/.virtualenvs
  71. XAUTHORITY=/home/pi/.Xauthority
  72. XDG_CONFIG_DIRS=/etc/xdg
  73. XDG_CONFIG_HOME=/home/pi/.config
  74. XDG_CURRENT_DESKTOP=LXDE
  75. XDG_DATA_DIRS=/usr/share/fkms:/usr/local/share:/usr/share/raspi-ui-overrides:/usr/share:/usr/share/gdm:/var/lib/menu-xdg
  76. XDG_GREETER_DATA_DIR=/var/lib/lightdm/data/pi
  77. XDG_MENU_PREFIX=lxde-pi-
  78. XDG_RUNTIME_DIR=/run/user/1000
  79. XDG_SEAT=seat0
  80. XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
  81. XDG_SESSION_CLASS=user
  82. XDG_SESSION_DESKTOP=lightdm-xsession
  83. XDG_SESSION_ID=c1
  84. XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
  85. XDG_SESSION_TYPE=x11
  86. XDG_VTNR=7
  87. _=./testing.sh
  88. _LXSESSION_PID=583
  89. __git_printf_supports_v=yes
  90. _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
  91. _xspecs=([lokalize]="!*.po" [acroread]="!*.[pf]df" [lbzcat]="!*.?(t)bz?(2)" [mpg321]="!*.mp3" [bzcat]="!*.?(t)bz?(2)" [oocalc]="!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)" [tex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [unlzma]="!*.@(tlz|lzma)" [sxemacs]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [aviplay]="!*.@(avi|asf|wmv)" [lbunzip2]="!*.?(t)bz?(2)" [dragon]="!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmvx]|OG[AGMVX]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9]).@(vdr|VDR))?(.part)" [freeamp]="!*.@(mp3|og[ag]|pls|m3u)" [rgvim]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [ooimpress]="!*.@(sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|?(f)odp|otp)" [gqmpeg]="!*.@(mp3|og[ag]|pls|m3u)" [texi2html]="!*.texi*" [hbpp]="!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])" [lowriter]="!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)" [qiv]="!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|svg)" [xanim]="!*.@(mpg|mpeg|avi|mov|qt)" [ps2pdfwr]="!*.@(?(e)ps|pdf)" [harbour]="!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])" [jadetex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [lodraw]="!*.@(sxd|std|sda|sdd|?(f)odg|otg)" [dvitype]="!*.dvi" [lobase]="!*.odb" [rpm2cpio]="!*.[rs]pm" [xine]="!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmvx]|OG[AGMVX]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))?(.part)" [lualatex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [localc]="!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)" [hbrun]="!*.[Hh][Rr][Bb]" [amaya]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [gv]="!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [unpigz]="!*.@(Z|[gGdz]z|t[ag]z)" [mozilla]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [epdfview]="!*.pdf" [dvips]="!*.dvi" [pdfunite]="!*.pdf" [ps2pdf14]="!*.@(?(e)ps|pdf)" [kid3]="!*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)" [vi]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [ps2pdf]="!*.@(?(e)ps|pdf)" [gpdf]="!*.[pf]df" [lilypond]="!*.ly" [texi2dvi]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [modplug123]="!*.@(669|abc|am[fs]|d[bs]m|dmf|far|it|mdl|m[eo]d|mid?(i)|mt[2m]|oct|okt?(a)|p[st]m|s[3t]m|ult|umx|wav|xm)" [znew]="*.Z" [ps2pdf13]="!*.@(?(e)ps|pdf)" [ps2pdf12]="!*.@(?(e)ps|pdf)" [kwrite]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [latex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [kate]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [pbzcat]="!*.?(t)bz?(2)" [poedit]="!*.po" [view]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [firefox]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])" [mozilla-firefox]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])" [kid3-qt]="!*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)" [luatex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [bunzip2]="!*.?(t)bz?(2)" [chromium-browser]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])" [dvipdfm]="!*.dvi" [kbabel]="!*.po" [ly2dvi]="!*.ly" [oodraw]="!*.@(sxd|std|sda|sdd|?(f)odg|otg)" [bzme]="!*.@(zip|z|gz|tgz)" [rgview]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [pdftex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [xemacs]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [zathura]="!*.@(cb[rz7t]|djv?(u)|?(e)ps|pdf)" [unxz]="!*.@(?(t)xz|tlz|lzma)" [rvim]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [madplay]="!*.mp3" [xetex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [gvim]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [kaffeine]="!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmvx]|OG[AGMVX]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9]).@(vdr|VDR))?(.part)" [dviselect]="!*.dvi" [kpdf]="!*.@(?(e)ps|pdf)" [bibtex]="!*.aux" [realplay]="!*.@(rm?(j)|ra?(m)|smi?(l))" [mpg123]="!*.mp3" [netscape]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [lzegrep]="!*.@(tlz|lzma)" [gview]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [kdvi]="!*.@(dvi|DVI)?(.@(gz|Z|bz2))" [xv]="!*.@(gif|jp?(e)g?(2)|j2[ck]|jp[2f]|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|?(e)ps)" [lzfgrep]="!*.@(tlz|lzma)" [playmidi]="!*.@(mid?(i)|cmf)" [lzless]="!*.@(tlz|lzma)" [elinks]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [timidity]="!*.@(mid?(i)|rmi|rcp|[gr]36|g18|mod|xm|it|x3m|s[3t]m|kar)" [xdvi]="!*.@(dvi|DVI)?(.@(gz|Z|bz2))" [xfig]="!*.fig" [xpdf]="!*.@(pdf|fdf)?(.@(gz|GZ|bz2|BZ2|Z))" [lomath]="!*.@(sxm|smf|mml|odf)" [lzcat]="!*.@(tlz|lzma)" [compress]="*.Z" [pdfjadetex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [kghostview]="!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [zcat]="!*.@(Z|[gGd]z|t[ag]z)" [pbunzip2]="!*.?(t)bz?(2)" [oobase]="!*.odb" [cdiff]="!*.@(dif?(f)|?(d)patch)?(.@([gx]z|bz2|lzma))" [iceweasel]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])" [gtranslator]="!*.po" [lynx]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [emacs]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [zipinfo]="!*.@(zip|[egjsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|ipa|do[ct][xm]|p[op]t[mx]|xl[st][xm]|pyz)" [google-chrome]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])" [xelatex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [uncompress]="!*.Z" [xzcat]="!*.@(?(t)xz|tlz|lzma)" [unzip]="!*.@(zip|[egjsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|ipa|do[ct][xm]|p[op]t[mx]|xl[st][xm]|pyz)" [rview]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [ogg123]="!*.@(og[ag]|m3u|flac|spx)" [lrunzip]="!*.lrz" [lzgrep]="!*.@(tlz|lzma)" [slitex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [vim]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [ggv]="!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [ee]="!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx)" [oomath]="!*.@(sxm|smf|mml|odf)" [aaxine]="!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmvx]|OG[AGMVX]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))?(.part)" [dvipdfmx]="!*.dvi" [advi]="!*.dvi" [gunzip]="!*.@(Z|[gGd]z|t[ag]z)" [makeinfo]="!*.texi*" [gharbour]="!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])" [okular]="!*.@(okular|@(?(e|x)ps|?(E|X)PS|[pf]df|[PF]DF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|epub|EPUB|odt|ODT|fb?(2)|FB?(2)|mobi|MOBI|g3|G3|chm|CHM)?(.?(gz|GZ|bz2|BZ2)))" [galeon]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [pdflatex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [lzmore]="!*.@(tlz|lzma)" [portecle]="!@(*.@(ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath|pem|p10|csr|crl)|cacerts)" [oowriter]="!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)" [loimpress]="!*.@(sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|?(f)odp|otp)" [epiphany]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [modplugplay]="!*.@(669|abc|am[fs]|d[bs]m|dmf|far|it|mdl|m[eo]d|mid?(i)|mt[2m]|oct|okt?(a)|p[st]m|s[3t]m|ult|umx|wav|xm)" [dvipdf]="!*.dvi" [dillo]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [fbxine]="!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmvx]|OG[AGMVX]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))?(.part)" )
  92. __expand_tilde_by_ref ()
  93. {
  94.     if [[ ${!1} == \~* ]]; then
  95.         eval $1=$(printf ~%q "${!1#\~}");
  96.     fi
  97. }
  98. __get_cword_at_cursor_by_ref ()
  99. {
  100.     local cword words=();
  101.     __reassemble_comp_words_by_ref "$1" words cword;
  102.     local i cur index=$COMP_POINT lead=${COMP_LINE:0:$COMP_POINT};
  103.     if [[ $index -gt 0 && ( -n $lead && -n ${lead//[[:space:]]} ) ]]; then
  104.         cur=$COMP_LINE;
  105.         for ((i = 0; i <= cword; ++i ))
  106.         do
  107.             while [[ ${#cur} -ge ${#words[i]} && "${cur:0:${#words[i]}}" != "${words[i]}" ]]; do
  108.                 cur="${cur:1}";
  109.                 [[ $index -gt 0 ]] && ((index--));
  110.             done;
  111.             if [[ $i -lt $cword ]]; then
  112.                 local old_size=${#cur};
  113.                 cur="${cur#"${words[i]}"}";
  114.                local new_size=${#cur};
  115.                index=$(( index - old_size + new_size ));
  116.            fi;
  117.        done;
  118.        [[ -n $cur && ! -n ${cur//[[:space:]]} ]] && cur=;
  119.        [[ $index -lt 0 ]] && index=0;
  120.    fi;
  121.    local "$2" "$3" "$4" && _upvars -a${#words[@]} $2 "${words[@]}" -v $3 "$cword" -v $4 "${cur:0:$index}"
  122. }
  123. __git_eread ()
  124. {
  125.    test -r "$1" && IFS='
  126. ' read "$2" < "$1"
  127. }
  128. __git_ps1 ()
  129. {
  130.    local exit=$?;
  131.    local pcmode=no;
  132.    local detached=no;
  133.    local ps1pc_start='\u@\h:\w ';
  134.    local ps1pc_end='\$ ';
  135.    local printf_format=' (%s)';
  136.    case "$#" in
  137.        2 | 3)
  138.            pcmode=yes;
  139.            ps1pc_start="$1";
  140.            ps1pc_end="$2";
  141.            printf_format="${3:-$printf_format}";
  142.            PS1="$ps1pc_start$ps1pc_end"
  143.        ;;
  144.        0 | 1)
  145.            printf_format="${1:-$printf_format}"
  146.        ;;
  147.        *)
  148.            return $exit
  149.        ;;
  150.    esac;
  151.    local ps1_expanded=yes;
  152.    [ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no;
  153.    [ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no;
  154.    local repo_info rev_parse_exit_code;
  155.     repo_info="$(git rev-parse --git-dir --is-inside-git-dir        --is-bare-repository --is-inside-work-tree      --short HEAD 2>/dev/null)";
  156.    rev_parse_exit_code="$?";
  157.    if [ -z "$repo_info" ]; then
  158.        return $exit;
  159.    fi;
  160.    local short_sha="";
  161.    if [ "$rev_parse_exit_code" = "0" ]; then
  162.        short_sha="${repo_info##*
  163. }";
  164.        repo_info="${repo_info%
  165. *}";
  166.    fi;
  167.    local inside_worktree="${repo_info##*
  168. }";
  169.    repo_info="${repo_info%
  170. *}";
  171.    local bare_repo="${repo_info##*
  172. }";
  173.    repo_info="${repo_info%
  174. *}";
  175.    local inside_gitdir="${repo_info##*
  176. }";
  177.    local g="${repo_info%
  178. *}";
  179.    if [ "true" = "$inside_worktree" ] && [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] && [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] && git check-ignore -q .; then
  180.        return $exit;
  181.    fi;
  182.    local r="";
  183.    local b="";
  184.    local step="";
  185.    local total="";
  186.    if [ -d "$g/rebase-merge" ]; then
  187.        __git_eread "$g/rebase-merge/head-name" b;
  188.        __git_eread "$g/rebase-merge/msgnum" step;
  189.        __git_eread "$g/rebase-merge/end" total;
  190.        if [ -f "$g/rebase-merge/interactive" ]; then
  191.            r="|REBASE-i";
  192.        else
  193.            r="|REBASE-m";
  194.        fi;
  195.    else
  196.        if [ -d "$g/rebase-apply" ]; then
  197.            __git_eread "$g/rebase-apply/next" step;
  198.            __git_eread "$g/rebase-apply/last" total;
  199.            if [ -f "$g/rebase-apply/rebasing" ]; then
  200.                __git_eread "$g/rebase-apply/head-name" b;
  201.                r="|REBASE";
  202.            else
  203.                if [ -f "$g/rebase-apply/applying" ]; then
  204.                    r="|AM";
  205.                else
  206.                    r="|AM/REBASE";
  207.                fi;
  208.            fi;
  209.        else
  210.            if [ -f "$g/MERGE_HEAD" ]; then
  211.                r="|MERGING";
  212.            else
  213.                if [ -f "$g/CHERRY_PICK_HEAD" ]; then
  214.                    r="|CHERRY-PICKING";
  215.                else
  216.                    if [ -f "$g/REVERT_HEAD" ]; then
  217.                        r="|REVERTING";
  218.                    else
  219.                        if [ -f "$g/BISECT_LOG" ]; then
  220.                            r="|BISECTING";
  221.                        fi;
  222.                    fi;
  223.                fi;
  224.            fi;
  225.        fi;
  226.        if [ -n "$b" ]; then
  227.            :;
  228.        else
  229.            if [ -h "$g/HEAD" ]; then
  230.                b="$(git symbolic-ref HEAD 2>/dev/null)";
  231.            else
  232.                local head="";
  233.                if ! __git_eread "$g/HEAD" head; then
  234.                    return $exit;
  235.                fi;
  236.                b="${head#ref: }";
  237.                if [ "$head" = "$b" ]; then
  238.                    detached=yes;
  239.                    b="$(
  240.                 case "${GIT_PS1_DESCRIBE_STYLE-}" in
  241.                 (contains)
  242.                     git describe --contains HEAD ;;
  243.                 (branch)
  244.                     git describe --contains --all HEAD ;;
  245.                 (tag)
  246.                     git describe --tags HEAD ;;
  247.                 (describe)
  248.                     git describe HEAD ;;
  249.                 (* | default)
  250.                     git describe --tags --exact-match HEAD ;;
  251.                 esac 2>/dev/null)" || b="$short_sha...";
  252.                    b="($b)";
  253.                fi;
  254.            fi;
  255.        fi;
  256.    fi;
  257.    if [ -n "$step" ] && [ -n "$total" ]; then
  258.        r="$r $step/$total";
  259.    fi;
  260.    local w="";
  261.    local i="";
  262.    local s="";
  263.    local u="";
  264.    local c="";
  265.    local p="";
  266.    if [ "true" = "$inside_gitdir" ]; then
  267.        if [ "true" = "$bare_repo" ]; then
  268.            c="BARE:";
  269.        else
  270.            b="GIT_DIR!";
  271.        fi;
  272.    else
  273.        if [ "true" = "$inside_worktree" ]; then
  274.            if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] && [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
  275.                git diff --no-ext-diff --quiet || w="*";
  276.                git diff --no-ext-diff --cached --quiet || i="+";
  277.                if [ -z "$short_sha" ] && [ -z "$i" ]; then
  278.                    i="#";
  279.                 fi;
  280.             fi;
  281.             if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] && git rev-parse --verify --quiet refs/stash > /dev/null; then
  282.                 s="$";
  283.             fi;
  284.             if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] && [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] && git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' > /dev/null 2> /dev/null; then
  285.                 u="%${ZSH_VERSION+%}";
  286.             fi;
  287.             if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
  288.                 __git_ps1_show_upstream;
  289.             fi;
  290.         fi;
  291.     fi;
  292.     local z="${GIT_PS1_STATESEPARATOR-" "}";
  293.     if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
  294.         __git_ps1_colorize_gitstring;
  295.     fi;
  296.     b=${b##refs/heads/};
  297.     if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
  298.         __git_ps1_branch_name=$b;
  299.         b="\${__git_ps1_branch_name}";
  300.     fi;
  301.     local f="$w$i$s$u";
  302.     local gitstring="$c$b${f:+$z$f}$r$p";
  303.     if [ $pcmode = yes ]; then
  304.         if [ "${__git_printf_supports_v-}" != yes ]; then
  305.             gitstring=$(printf -- "$printf_format" "$gitstring");
  306.         else
  307.             printf -v gitstring -- "$printf_format" "$gitstring";
  308.         fi;
  309.         PS1="$ps1pc_start$gitstring$ps1pc_end";
  310.     else
  311.         printf -- "$printf_format" "$gitstring";
  312.     fi;
  313.     return $exit
  314. }
  315. __git_ps1_colorize_gitstring ()
  316. {
  317.     if [[ -n ${ZSH_VERSION-} ]]; then
  318.         local c_red='%F{red}';
  319.         local c_green='%F{green}';
  320.         local c_lblue='%F{blue}';
  321.         local c_clear='%f';
  322.     else
  323.         local c_red='\[\e[31m\]';
  324.         local c_green='\[\e[32m\]';
  325.         local c_lblue='\[\e[1;34m\]';
  326.         local c_clear='\[\e[0m\]';
  327.     fi;
  328.     local bad_color=$c_red;
  329.     local ok_color=$c_green;
  330.     local flags_color="$c_lblue";
  331.     local branch_color="";
  332.     if [ $detached = no ]; then
  333.         branch_color="$ok_color";
  334.     else
  335.         branch_color="$bad_color";
  336.     fi;
  337.     c="$branch_color$c";
  338.     z="$c_clear$z";
  339.     if [ "$w" = "*" ]; then
  340.         w="$bad_color$w";
  341.     fi;
  342.     if [ -n "$i" ]; then
  343.         i="$ok_color$i";
  344.     fi;
  345.     if [ -n "$s" ]; then
  346.         s="$flags_color$s";
  347.     fi;
  348.     if [ -n "$u" ]; then
  349.         u="$bad_color$u";
  350.     fi;
  351.     r="$c_clear$r"
  352. }
  353. __git_ps1_show_upstream ()
  354. {
  355.     local key value;
  356.     local svn_remote svn_url_pattern count n;
  357.     local upstream=git legacy="" verbose="" name="";
  358.     svn_remote=();
  359.     local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')";
  360.     while read -r key value; do
  361.         case "$key" in
  362.             bash.showupstream)
  363.                 GIT_PS1_SHOWUPSTREAM="$value";
  364.                 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
  365.                     p="";
  366.                     return;
  367.                 fi
  368.             ;;
  369.             svn-remote.*.url)
  370.                 svn_remote[$((${#svn_remote[@]} + 1))]="$value";
  371.                 svn_url_pattern="$svn_url_pattern\\|$value";
  372.                 upstream=svn+git
  373.             ;;
  374.         esac;
  375.     done <<< "$output";
  376.     for option in ${GIT_PS1_SHOWUPSTREAM};
  377.     do
  378.         case "$option" in
  379.             git | svn)
  380.                 upstream="$option"
  381.             ;;
  382.             verbose)
  383.                 verbose=1
  384.             ;;
  385.             legacy)
  386.                 legacy=1
  387.             ;;
  388.             name)
  389.                 name=1
  390.             ;;
  391.         esac;
  392.     done;
  393.     case "$upstream" in
  394.         git)
  395.             upstream="@{upstream}"
  396.         ;;
  397.         svn*)
  398.             local -a svn_upstream;
  399.             svn_upstream=($(git log --first-parent -1                   --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null));
  400.             if [[ 0 -ne ${#svn_upstream[@]} ]]; then
  401.                 svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]};
  402.                 svn_upstream=${svn_upstream%@*};
  403.                 local n_stop="${#svn_remote[@]}";
  404.                 for ((n=1; n <= n_stop; n++))
  405.                 do
  406.                     svn_upstream=${svn_upstream#${svn_remote[$n]}};
  407.                 done;
  408.                 if [[ -z "$svn_upstream" ]]; then
  409.                     upstream=${GIT_SVN_ID:-git-svn};
  410.                 else
  411.                     upstream=${svn_upstream#/};
  412.                 fi;
  413.             else
  414.                 if [[ "svn+git" = "$upstream" ]]; then
  415.                     upstream="@{upstream}";
  416.                 fi;
  417.             fi
  418.         ;;
  419.     esac;
  420.     if [[ -z "$legacy" ]]; then
  421.         count="$(git rev-list --count --left-right              "$upstream"...HEAD 2>/dev/null)";
  422.     else
  423.         local commits;
  424.         if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"; then
  425.             local commit behind=0 ahead=0;
  426.             for commit in $commits;
  427.             do
  428.                 case "$commit" in
  429.                     "<"*)
  430.                         ((behind++))
  431.                     ;;
  432.                     *)
  433.                         ((ahead++))
  434.                     ;;
  435.                 esac;
  436.             done;
  437.             count="$behind  $ahead";
  438.         else
  439.             count="";
  440.         fi;
  441.     fi;
  442.     if [[ -z "$verbose" ]]; then
  443.         case "$count" in
  444.             "")
  445.                 p=""
  446.             ;;
  447.             "0  0")
  448.                 p="="
  449.             ;;
  450.             "0  "*)
  451.                 p=">"
  452.             ;;
  453.             *"  0")
  454.                 p="<"
  455.             ;;
  456.             *)
  457.                 p="<>"
  458.             ;;
  459.         esac;
  460.     else
  461.         case "$count" in
  462.             "")
  463.                 p=""
  464.             ;;
  465.             "0  0")
  466.                 p=" u="
  467.             ;;
  468.             "0  "*)
  469.                 p=" u+${count#0 }"
  470.             ;;
  471.             *"  0")
  472.                 p=" u-${count%  0}"
  473.             ;;
  474.             *)
  475.                 p=" u+${count#* }-${count%  *}"
  476.             ;;
  477.         esac;
  478.         if [[ -n "$count" && -n "$name" ]]; then
  479.             __git_ps1_upstream_name=$(git rev-parse                 --abbrev-ref "$upstream" 2>/dev/null);
  480.             if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
  481.                 p="$p \${__git_ps1_upstream_name}";
  482.             else
  483.                 p="$p ${__git_ps1_upstream_name}";
  484.                 unset __git_ps1_upstream_name;
  485.             fi;
  486.         fi;
  487.     fi
  488. }
  489. __load_completion ()
  490. {
  491.     local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions);
  492.     local OIFS=$IFS IFS=: dir cmd="${1##*/}" compfile;
  493.     [[ -n $cmd ]] || return 1;
  494.     for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share};
  495.     do
  496.         dirs+=($dir/bash-completion/completions);
  497.     done;
  498.     IFS=$OIFS;
  499.     if [[ $BASH_SOURCE == */* ]]; then
  500.         dirs+=("${BASH_SOURCE%/*}/completions");
  501.     else
  502.         dirs+=(./completions);
  503.     fi;
  504.     for dir in "${dirs[@]}";
  505.     do
  506.         for compfile in "$cmd" "$cmd.bash" "_$cmd";
  507.         do
  508.             compfile="$dir/$compfile";
  509.             [[ -f "$compfile" ]] && . "$compfile" &> /dev/null && return 0;
  510.         done;
  511.     done;
  512.     [[ -n "${_xspecs[$cmd]}" ]] && complete -F _filedir_xspec "$cmd" && return 0;
  513.     return 1
  514. }
  515. __ltrim_colon_completions ()
  516. {
  517.     if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
  518.         local colon_word=${1%"${1##*:}"};
  519.        local i=${#COMPREPLY[*]};
  520.        while [[ $((--i)) -ge 0 ]]; do
  521.            COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"};
  522.        done;
  523.    fi
  524. }
  525. __parse_options ()
  526. {
  527.     local option option2 i IFS='    
  528. ,/|';
  529.    option=;
  530.    local -a array;
  531.    read -a array <<< "$1";
  532.    for i in "${array[@]}";
  533.    do
  534.        case "$i" in
  535.            ---*)
  536.                break
  537.            ;;
  538.            --?*)
  539.                option=$i;
  540.                break
  541.            ;;
  542.            -?*)
  543.                [[ -n $option ]] || option=$i
  544.            ;;
  545.            *)
  546.                break
  547.            ;;
  548.        esac;
  549.    done;
  550.    [[ -n $option ]] || return;
  551.     IFS='  
  552. ';
  553.    if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
  554.        option2=${option/"${BASH_REMATCH[1]}"/};
  555.         option2=${option2%%[<{().[]*};
  556.         printf '%s\n' "${option2/=*/=}";
  557.         option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"};
  558.    fi;
  559.    option=${option%%[<{().[]*};
  560.    printf '%s\n' "${option/=*/=}"
  561. }
  562. __reassemble_comp_words_by_ref ()
  563. {
  564.    local exclude i j line ref;
  565.    if [[ -n $1 ]]; then
  566.        exclude="${1//[^$COMP_WORDBREAKS]}";
  567.    fi;
  568.    printf -v "$3" %s "$COMP_CWORD";
  569.    if [[ -n $exclude ]]; then
  570.        line=$COMP_LINE;
  571.        for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++))
  572.        do
  573.            while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do
  574.                [[ $line != [[:blank:]]* ]] && (( j >= 2 )) && ((j--));
  575.                ref="$2[$j]";
  576.                printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}";
  577.                [[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j";
  578.                line=${line#*"${COMP_WORDS[$i]}"};
  579.                 [[ $line == [[:blank:]]* ]] && ((j++));
  580.                 (( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2;
  581.             done;
  582.             ref="$2[$j]";
  583.             printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}";
  584.             line=${line#*"${COMP_WORDS[i]}"};
  585.            [[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j";
  586.        done;
  587.        [[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j";
  588.    else
  589.        for i in ${!COMP_WORDS[@]};
  590.        do
  591.            printf -v "$2[i]" %s "${COMP_WORDS[i]}";
  592.        done;
  593.    fi
  594. }
  595. _allowed_groups ()
  596. {
  597.    if _complete_as_root; then
  598.        local IFS='
  599. ';
  600.        COMPREPLY=($( compgen -g -- "$1" ));
  601.    else
  602.        local IFS='
  603. ';
  604.        COMPREPLY=($( compgen -W             "$( id -Gn 2>/dev/null || groups 2>/dev/null )" -- "$1" ));
  605.     fi
  606. }
  607. _allowed_users ()
  608. {
  609.     if _complete_as_root; then
  610.         local IFS='
  611. ';
  612.         COMPREPLY=($( compgen -u -- "${1:-$cur}" ));
  613.     else
  614.         local IFS='
  615. ';
  616.         COMPREPLY=($( compgen -W             "$( id -un 2>/dev/null || whoami 2>/dev/null )" -- "${1:-$cur}" ));
  617.     fi
  618. }
  619. _available_interfaces ()
  620. {
  621.     local PATH=$PATH:/sbin;
  622.     COMPREPLY=($( {
  623.         if [[ ${1:-} == -w ]]; then
  624.             iwconfig
  625.         elif [[ ${1:-} == -a ]]; then
  626.             ifconfig || ip link show up
  627.         else
  628.             ifconfig -a || ip link show
  629.         fi
  630.     } 2>/dev/null | awk         '/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }' ));
  631.     COMPREPLY=($( compgen -W '${COMPREPLY[@]/%[[:punct:]]/}' -- "$cur" ))
  632. }
  633. _cd ()
  634. {
  635.     local cur prev words cword;
  636.     _init_completion || return;
  637.     local IFS='
  638. ' i j k;
  639.     compopt -o filenames;
  640.     if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
  641.         _filedir -d;
  642.         return;
  643.     fi;
  644.     local -r mark_dirs=$(_rl_enabled mark-directories && echo y);
  645.     local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y);
  646.     for i in ${CDPATH//:/'
  647. '};
  648.     do
  649.         k="${#COMPREPLY[@]}";
  650.         for j in $( compgen -d -- $i/$cur );
  651.         do
  652.             if [[ ( -n $mark_symdirs && -h $j || -n $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
  653.                 j+="/";
  654.             fi;
  655.             COMPREPLY[k++]=${j#$i/};
  656.         done;
  657.     done;
  658.     _filedir -d;
  659.     if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
  660.         i=${COMPREPLY[0]};
  661.         if [[ "$i" == "$cur" && $i != "*/" ]]; then
  662.             COMPREPLY[0]="${i}/";
  663.         fi;
  664.     fi;
  665.     return
  666. }
  667. _cd_devices ()
  668. {
  669.     COMPREPLY+=($( compgen -f -d -X "!*/?([amrs])cd*" -- "${cur:-/dev/}" ))
  670. }
  671. _cdsitepackages_complete ()
  672. {
  673.     local cur="$2";
  674.     COMPREPLY=($(cdsitepackages && compgen -d -- "${cur}" ))
  675. }
  676. _cdvirtualenv_complete ()
  677. {
  678.     local cur="$2";
  679.     COMPREPLY=($(cdvirtualenv && compgen -d -- "${cur}" ))
  680. }
  681. _command ()
  682. {
  683.     local offset i;
  684.     offset=1;
  685.     for ((i=1; i <= COMP_CWORD; i++ ))
  686.     do
  687.         if [[ "${COMP_WORDS[i]}" != -* ]]; then
  688.             offset=$i;
  689.             break;
  690.         fi;
  691.     done;
  692.     _command_offset $offset
  693. }
  694. _command_offset ()
  695. {
  696.     local word_offset=$1 i j;
  697.     for ((i=0; i < $word_offset; i++ ))
  698.     do
  699.         for ((j=0; j <= ${#COMP_LINE}; j++ ))
  700.         do
  701.             [[ "$COMP_LINE" == "${COMP_WORDS[i]}"* ]] && break;
  702.             COMP_LINE=${COMP_LINE:1};
  703.             ((COMP_POINT--));
  704.         done;
  705.         COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"};
  706.        ((COMP_POINT-=${#COMP_WORDS[i]}));
  707.    done;
  708.    for ((i=0; i <= COMP_CWORD - $word_offset; i++ ))
  709.    do
  710.        COMP_WORDS[i]=${COMP_WORDS[i+$word_offset]};
  711.    done;
  712.    for ((i; i <= COMP_CWORD; i++ ))
  713.    do
  714.        unset 'COMP_WORDS[i]';
  715.    done;
  716.    ((COMP_CWORD -= $word_offset));
  717.    COMPREPLY=();
  718.    local cur;
  719.    _get_comp_words_by_ref cur;
  720.    if [[ $COMP_CWORD -eq 0 ]]; then
  721.        local IFS='
  722. ';
  723.        compopt -o filenames;
  724.        COMPREPLY=($( compgen -d -c -- "$cur" ));
  725.    else
  726.        local cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]};
  727.        local cspec=$( complete -p $cmd 2>/dev/null );
  728.        if [[ ! -n $cspec && $cmd == */* ]]; then
  729.            cspec=$( complete -p ${cmd##*/} 2>/dev/null );
  730.            [[ -n $cspec ]] && compcmd=${cmd##*/};
  731.        fi;
  732.        if [[ ! -n $cspec ]]; then
  733.            compcmd=${cmd##*/};
  734.            _completion_loader $compcmd;
  735.            cspec=$( complete -p $compcmd 2>/dev/null );
  736.        fi;
  737.        if [[ -n $cspec ]]; then
  738.            if [[ ${cspec#* -F } != $cspec ]]; then
  739.                local func=${cspec#*-F };
  740.                func=${func%% *};
  741.                if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
  742.                    $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}";
  743.                else
  744.                    $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}";
  745.                fi;
  746.                local opt;
  747.                while [[ $cspec == *" -o "* ]]; do
  748.                    cspec=${cspec#*-o };
  749.                    opt=${cspec%% *};
  750.                    compopt -o $opt;
  751.                    cspec=${cspec#$opt};
  752.                done;
  753.            else
  754.                cspec=${cspec#complete};
  755.                cspec=${cspec%%$compcmd};
  756.                COMPREPLY=($( eval compgen "$cspec" -- '$cur' ));
  757.            fi;
  758.        else
  759.            if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
  760.                _minimal;
  761.            fi;
  762.        fi;
  763.    fi
  764. }
  765. _complete_as_root ()
  766. {
  767.    [[ $EUID -eq 0 || -n ${root_command:-} ]]
  768. }
  769. _completion_loader ()
  770. {
  771.    local cmd="${1:-_EmptycmD_}";
  772.    __load_completion "$cmd" && return 124;
  773.    complete -F _minimal -- "$cmd" && return 124
  774. }
  775. _configured_interfaces ()
  776. {
  777.    if [[ -f /etc/debian_version ]]; then
  778.        COMPREPLY=($( compgen -W "$( command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p'            /etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null )"             -- "$cur" ));
  779.     else
  780.         if [[ -f /etc/SuSE-release ]]; then
  781.             COMPREPLY=($( compgen -W "$( printf '%s\n'             /etc/sysconfig/network/ifcfg-* |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
  782.         else
  783.             if [[ -f /etc/pld-release ]]; then
  784.                 COMPREPLY=($( compgen -W "$( command ls -B             /etc/sysconfig/interfaces |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
  785.             else
  786.                 COMPREPLY=($( compgen -W "$( printf '%s\n'             /etc/sysconfig/network-scripts/ifcfg-* |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
  787.             fi;
  788.         fi;
  789.     fi
  790. }
  791. _count_args ()
  792. {
  793.     local i cword words;
  794.     __reassemble_comp_words_by_ref "$1" words cword;
  795.     args=1;
  796.     for i in "${words[@]:1:cword-1}";
  797.     do
  798.         [[ "$i" != -* ]] && args=$(($args+1));
  799.     done
  800. }
  801. _dvd_devices ()
  802. {
  803.     COMPREPLY+=($( compgen -f -d -X "!*/?(r)dvd*" -- "${cur:-/dev/}" ))
  804. }
  805. _expand ()
  806. {
  807.     if [[ "$cur" == \~*/* ]]; then
  808.         __expand_tilde_by_ref cur;
  809.     else
  810.         if [[ "$cur" == \~* ]]; then
  811.             _tilde "$cur" || eval COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}");
  812.             return ${#COMPREPLY[@]};
  813.         fi;
  814.     fi
  815. }
  816. _filedir ()
  817. {
  818.     local IFS='
  819. ';
  820.     _tilde "$cur" || return;
  821.     local -a toks;
  822.     local x reset;
  823.     reset=$(shopt -po noglob);
  824.     set -o noglob;
  825.     toks=($( compgen -d -- "$cur" ));
  826.     eval $reset;
  827.     if [[ "$1" != -d ]]; then
  828.         local quoted;
  829.         _quote_readline_by_ref "$cur" quoted;
  830.         local xspec=${1:+"!*.@($1|${1^^})"};
  831.        reset=$(shopt -po noglob);
  832.        set -o noglob;
  833.        toks+=($( compgen -f -X "$xspec" -- $quoted ));
  834.        eval $reset;
  835.        [[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && {
  836.            reset=$(shopt -po noglob);
  837.            set -o noglob;
  838.            toks+=($( compgen -f -- $quoted ));
  839.            eval $reset
  840.        };
  841.    fi;
  842.    if [[ ${#toks[@]} -ne 0 ]]; then
  843.        compopt -o filenames 2> /dev/null;
  844.        COMPREPLY+=("${toks[@]}");
  845.    fi
  846. }
  847. _filedir_xspec ()
  848. {
  849.    local cur prev words cword;
  850.    _init_completion || return;
  851.    _tilde "$cur" || return;
  852.    local IFS='
  853. ' xspec=${_xspecs[${1##*/}]} tmp;
  854.    local -a toks;
  855.    toks=($(
  856.        compgen -d -- "$(quote_readline "$cur")" | {
  857.        while read -r tmp; do
  858.            printf '%s\n' $tmp
  859.        done
  860.        }
  861.        ));
  862.    eval xspec="${xspec}";
  863.    local matchop=!;
  864.    if [[ $xspec == !* ]]; then
  865.        xspec=${xspec#!};
  866.        matchop=@;
  867.    fi;
  868.    xspec="$matchop($xspec|${xspec^^})";
  869.    toks+=($(
  870.        eval compgen -f -X "'!$xspec'" -- "\$(quote_readline "\$cur")" | {
  871.        while read -r tmp; do
  872.            [[ -n $tmp ]] && printf '%s\n' $tmp
  873.        done
  874.        }
  875.        ));
  876.    [[ -n ${COMP_FILEDIR_FALLBACK:-} && ${#toks[@]} -lt 1 ]] && {
  877.        local reset=$(shopt -po noglob);
  878.        set -o noglob;
  879.        toks+=($( compgen -f -- "$(quote_readline "$cur")" ));
  880.         IFS=' ';
  881.         $reset;
  882.         IFS='
  883. '
  884.     };
  885.     if [[ ${#toks[@]} -ne 0 ]]; then
  886.         compopt -o filenames;
  887.         COMPREPLY=("${toks[@]}");
  888.     fi
  889. }
  890. _fstypes ()
  891. {
  892.     local fss;
  893.     if [[ -e /proc/filesystems ]]; then
  894.         fss="$( cut -d' ' -f2 /proc/filesystems )
  895.            $( awk '! /\*/ { print $NF }' /etc/filesystems 2>/dev/null )";
  896.     else
  897.         fss="$( awk '/^[ \t]*[^#]/ { print $3 }' /etc/fstab 2>/dev/null )
  898.            $( awk '/^[ \t]*[^#]/ { print $3 }' /etc/mnttab 2>/dev/null )
  899.            $( awk '/^[ \t]*[^#]/ { print $4 }' /etc/vfstab 2>/dev/null )
  900.            $( awk '{ print $1 }' /etc/dfs/fstypes 2>/dev/null )
  901.            $( [[ -d /etc/fs ]] && command ls /etc/fs )";
  902.     fi;
  903.     [[ -n $fss ]] && COMPREPLY+=($( compgen -W "$fss" -- "$cur" ))
  904. }
  905. _get_comp_words_by_ref ()
  906. {
  907.     local exclude flag i OPTIND=1;
  908.     local cur cword words=();
  909.     local upargs=() upvars=() vcur vcword vprev vwords;
  910.     while getopts "c:i:n:p:w:" flag "$@"; do
  911.         case $flag in
  912.             c)
  913.                 vcur=$OPTARG
  914.             ;;
  915.             i)
  916.                 vcword=$OPTARG
  917.             ;;
  918.             n)
  919.                 exclude=$OPTARG
  920.             ;;
  921.             p)
  922.                 vprev=$OPTARG
  923.             ;;
  924.             w)
  925.                 vwords=$OPTARG
  926.             ;;
  927.         esac;
  928.     done;
  929.     while [[ $# -ge $OPTIND ]]; do
  930.         case ${!OPTIND} in
  931.             cur)
  932.                 vcur=cur
  933.             ;;
  934.             prev)
  935.                 vprev=prev
  936.             ;;
  937.             cword)
  938.                 vcword=cword
  939.             ;;
  940.             words)
  941.                 vwords=words
  942.             ;;
  943.             *)
  944.                 echo "bash: $FUNCNAME(): \`${!OPTIND}': unknown argument" 1>&2;
  945.                return 1
  946.            ;;
  947.        esac;
  948.        let "OPTIND += 1";
  949.    done;
  950.    __get_cword_at_cursor_by_ref "$exclude" words cword cur;
  951.    [[ -n $vcur ]] && {
  952.        upvars+=("$vcur");
  953.        upargs+=(-v $vcur "$cur")
  954.    };
  955.    [[ -n $vcword ]] && {
  956.        upvars+=("$vcword");
  957.        upargs+=(-v $vcword "$cword")
  958.    };
  959.    [[ -n $vprev && $cword -ge 1 ]] && {
  960.        upvars+=("$vprev");
  961.        upargs+=(-v $vprev "${words[cword - 1]}")
  962.    };
  963.    [[ -n $vwords ]] && {
  964.        upvars+=("$vwords");
  965.        upargs+=(-a${#words[@]} $vwords "${words[@]}")
  966.    };
  967.    (( ${#upvars[@]} )) && local "${upvars[@]}" && _upvars "${upargs[@]}"
  968. }
  969. _get_cword ()
  970. {
  971.    local LC_CTYPE=C;
  972.    local cword words;
  973.    __reassemble_comp_words_by_ref "$1" words cword;
  974.    if [[ -n ${2//[^0-9]/} ]]; then
  975.        printf "%s" "${words[cword-$2]}";
  976.    else
  977.        if [[ "${#words[cword]}" -eq 0 || "$COMP_POINT" == "${#COMP_LINE}" ]]; then
  978.            printf "%s" "${words[cword]}";
  979.        else
  980.            local i;
  981.            local cur="$COMP_LINE";
  982.            local index="$COMP_POINT";
  983.            for ((i = 0; i <= cword; ++i ))
  984.            do
  985.                while [[ "${#cur}" -ge ${#words[i]} && "${cur:0:${#words[i]}}" != "${words[i]}" ]]; do
  986.                    cur="${cur:1}";
  987.                    [[ $index -gt 0 ]] && ((index--));
  988.                done;
  989.                if [[ "$i" -lt "$cword" ]]; then
  990.                    local old_size="${#cur}";
  991.                    cur="${cur#${words[i]}}";
  992.                    local new_size="${#cur}";
  993.                    index=$(( index - old_size + new_size ));
  994.                fi;
  995.            done;
  996.            if [[ "${words[cword]:0:${#cur}}" != "$cur" ]]; then
  997.                printf "%s" "${words[cword]}";
  998.            else
  999.                printf "%s" "${cur:0:$index}";
  1000.            fi;
  1001.        fi;
  1002.    fi
  1003. }
  1004. _get_first_arg ()
  1005. {
  1006.    local i;
  1007.    arg=;
  1008.    for ((i=1; i < COMP_CWORD; i++ ))
  1009.    do
  1010.        if [[ "${COMP_WORDS[i]}" != -* ]]; then
  1011.            arg=${COMP_WORDS[i]};
  1012.            break;
  1013.        fi;
  1014.    done
  1015. }
  1016. _get_pword ()
  1017. {
  1018.    if [[ $COMP_CWORD -ge 1 ]]; then
  1019.        _get_cword "${@:-}" 1;
  1020.    fi
  1021. }
  1022. _gids ()
  1023. {
  1024.    if type getent &> /dev/null; then
  1025.        COMPREPLY=($( compgen -W '$( getent group | cut -d: -f3 )'             -- "$cur" ));
  1026.    else
  1027.        if type perl &> /dev/null; then
  1028.            COMPREPLY=($( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- "$cur" ));
  1029.        else
  1030.            COMPREPLY=($( compgen -W '$( cut -d: -f3 /etc/group )' -- "$cur" ));
  1031.        fi;
  1032.    fi
  1033. }
  1034. _have ()
  1035. {
  1036.    PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &> /dev/null
  1037. }
  1038. _included_ssh_config_files ()
  1039. {
  1040.    [[ $# -lt 1 ]] && echo "error: $FUNCNAME: missing mandatory argument CONFIG";
  1041.    local configfile i f;
  1042.    configfile=$1;
  1043.    local included=$( command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p' "${configfile}" );
  1044.    for i in ${included[@]};
  1045.    do
  1046.        if ! [[ "$i" =~ ^\~.*|^\/.* ]]; then
  1047.            if [[ "$configfile" =~ ^\/etc\/ssh.* ]]; then
  1048.                i="/etc/ssh/$i";
  1049.            else
  1050.                i="$HOME/.ssh/$i";
  1051.            fi;
  1052.        fi;
  1053.        __expand_tilde_by_ref i;
  1054.        for f in ${i};
  1055.        do
  1056.            if [ -r $f ]; then
  1057.                config+=("$f");
  1058.                _included_ssh_config_files $f;
  1059.            fi;
  1060.        done;
  1061.    done
  1062. }
  1063. _init_completion ()
  1064. {
  1065.    local exclude= flag outx errx inx OPTIND=1;
  1066.    while getopts "n:e:o:i:s" flag "$@"; do
  1067.        case $flag in
  1068.            n)
  1069.                exclude+=$OPTARG
  1070.            ;;
  1071.            e)
  1072.                errx=$OPTARG
  1073.            ;;
  1074.            o)
  1075.                outx=$OPTARG
  1076.            ;;
  1077.            i)
  1078.                inx=$OPTARG
  1079.            ;;
  1080.            s)
  1081.                split=false;
  1082.                exclude+==
  1083.            ;;
  1084.        esac;
  1085.    done;
  1086.    COMPREPLY=();
  1087.    local redir="@(?([0-9])<|?([0-9&])>?(>)|>&)";
  1088.    _get_comp_words_by_ref -n "$exclude<>&" cur prev words cword;
  1089.    _variables && return 1;
  1090.    if [[ $cur == $redir* || $prev == $redir ]]; then
  1091.        local xspec;
  1092.        case $cur in
  1093.            2'>'*)
  1094.                xspec=$errx
  1095.            ;;
  1096.            *'>'*)
  1097.                xspec=$outx
  1098.            ;;
  1099.            *'<'*)
  1100.                xspec=$inx
  1101.            ;;
  1102.            *)
  1103.                case $prev in
  1104.                    2'>'*)
  1105.                        xspec=$errx
  1106.                    ;;
  1107.                    *'>'*)
  1108.                        xspec=$outx
  1109.                    ;;
  1110.                    *'<'*)
  1111.                        xspec=$inx
  1112.                    ;;
  1113.                esac
  1114.            ;;
  1115.        esac;
  1116.        cur="${cur##$redir}";
  1117.        _filedir $xspec;
  1118.        return 1;
  1119.    fi;
  1120.    local i skip;
  1121.    for ((i=1; i < ${#words[@]}; 1))
  1122.    do
  1123.        if [[ ${words[i]} == $redir* ]]; then
  1124.            [[ ${words[i]} == $redir ]] && skip=2 || skip=1;
  1125.            words=("${words[@]:0:i}" "${words[@]:i+skip}");
  1126.            [[ $i -le $cword ]] && cword=$(( cword - skip ));
  1127.        else
  1128.            i=$(( ++i ));
  1129.        fi;
  1130.    done;
  1131.    [[ $cword -le 0 ]] && return 1;
  1132.    prev=${words[cword-1]};
  1133.    [[ -n ${split-} ]] && _split_longopt && split=true;
  1134.    return 0
  1135. }
  1136. _installed_modules ()
  1137. {
  1138.    COMPREPLY=($( compgen -W "$( PATH="$PATH:/sbin" lsmod |         awk '{if (NR != 1) print $1}' )" -- "$1" ))
  1139. }
  1140. _ip_addresses ()
  1141. {
  1142.    local PATH=$PATH:/sbin;
  1143.    COMPREPLY+=($( compgen -W         "$( { LC_ALL=C ifconfig -a || ip addr show; } 2>/dev/null | command sed -ne             's/.*addr:\([^[:space:]]*\).*/\1/p' -ne             's|.*inet[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p' )"         -- "$cur" ))
  1144. }
  1145. _kernel_versions ()
  1146. {
  1147.    COMPREPLY=($( compgen -W '$( command ls /lib/modules )' -- "$cur" ))
  1148. }
  1149. _known_hosts ()
  1150. {
  1151.    local cur prev words cword;
  1152.    _init_completion -n : || return;
  1153.    local options;
  1154.    [[ "$1" == -a || "$2" == -a ]] && options=-a;
  1155.    [[ "$1" == -c || "$2" == -c ]] && options+=" -c";
  1156.    _known_hosts_real $options -- "$cur"
  1157. }
  1158. _known_hosts_real ()
  1159. {
  1160.    local configfile flag prefix OIFS=$IFS;
  1161.    local cur user suffix aliases i host ipv4 ipv6;
  1162.    local -a kh tmpkh khd config;
  1163.    local OPTIND=1;
  1164.    while getopts "ac46F:p:" flag "$@"; do
  1165.        case $flag in
  1166.            a)
  1167.                aliases='yes'
  1168.            ;;
  1169.            c)
  1170.                suffix=':'
  1171.            ;;
  1172.            F)
  1173.                configfile=$OPTARG
  1174.            ;;
  1175.            p)
  1176.                prefix=$OPTARG
  1177.            ;;
  1178.            4)
  1179.                ipv4=1
  1180.            ;;
  1181.            6)
  1182.                ipv6=1
  1183.            ;;
  1184.        esac;
  1185.    done;
  1186.    [[ $# -lt $OPTIND ]] && echo "error: $FUNCNAME: missing mandatory argument CWORD";
  1187.    cur=${!OPTIND};
  1188.    let "OPTIND += 1";
  1189.    [[ $# -ge $OPTIND ]] && echo "error: $FUNCNAME("$@"): unprocessed arguments:" $(while [[ $# -ge $OPTIND ]]; do printf '%s\n' ${!OPTIND}; shift; done);
  1190.    [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@};
  1191.    kh=();
  1192.    if [[ -n $configfile ]]; then
  1193.        [[ -r $configfile ]] && config+=("$configfile");
  1194.    else
  1195.        for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config;
  1196.        do
  1197.            [[ -r $i ]] && config+=("$i");
  1198.        done;
  1199.    fi;
  1200.    for i in "${config[@]}";
  1201.    do
  1202.        _included_ssh_config_files "$i";
  1203.    done;
  1204.    if [[ ${#config[@]} -gt 0 ]]; then
  1205.        local IFS='
  1206. ' j;
  1207.        tmpkh=($( awk 'sub("^[ \t]*([Gg][Ll][Oo][Bb][Aa][Ll]|[Uu][Ss][Ee][Rr])[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee][ \t]+", "") { print $0 }' "${config[@]}" | sort -u ));
  1208.        IFS=$OIFS;
  1209.        for i in "${tmpkh[@]}";
  1210.        do
  1211.            while [[ $i =~ ^([^\"]*)\"([^\"]*)\"(.*)$ ]]; do
  1212.                i=${BASH_REMATCH[1]}${BASH_REMATCH[3]};
  1213.                j=${BASH_REMATCH[2]};
  1214.                __expand_tilde_by_ref j;
  1215.                [[ -r $j ]] && kh+=("$j");
  1216.            done;
  1217.            for j in $i;
  1218.            do
  1219.                __expand_tilde_by_ref j;
  1220.                [[ -r $j ]] && kh+=("$j");
  1221.            done;
  1222.        done;
  1223.    fi;
  1224.    if [[ -z $configfile ]]; then
  1225.        for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 /etc/known_hosts /etc/known_hosts2 ~/.ssh/known_hosts ~/.ssh/known_hosts2;
  1226.        do
  1227.            [[ -r $i ]] && kh+=("$i");
  1228.        done;
  1229.        for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys;
  1230.        do
  1231.            [[ -d $i ]] && khd+=("$i"/*pub);
  1232.        done;
  1233.    fi;
  1234.    if [[ ${#kh[@]} -gt 0 || ${#khd[@]} -gt 0 ]]; then
  1235.        if [[ ${#kh[@]} -gt 0 ]]; then
  1236.            for i in "${kh[@]}";
  1237.            do
  1238.                while read -ra tmpkh; do
  1239.                    set -- "${tmpkh[@]}";
  1240.                    [[ $1 == [\|\#]* ]] && continue;
  1241.                    [[ $1 == @* ]] && shift;
  1242.                    local IFS=,;
  1243.                    for host in $1;
  1244.                    do
  1245.                        [[ $host == *[*?]* ]] && continue;
  1246.                        host="${host#[}";
  1247.                        host="${host%]?(:+([0-9]))}";
  1248.                        COMPREPLY+=($host);
  1249.                    done;
  1250.                    IFS=$OIFS;
  1251.                done < "$i";
  1252.            done;
  1253.            COMPREPLY=($( compgen -W '${COMPREPLY[@]}' -- "$cur" ));
  1254.        fi;
  1255.        if [[ ${#khd[@]} -gt 0 ]]; then
  1256.            for i in "${khd[@]}";
  1257.            do
  1258.                if [[ "$i" == *key_22_$cur*.pub && -r "$i" ]]; then
  1259.                    host=${i/#*key_22_/};
  1260.                    host=${host/%.pub/};
  1261.                    COMPREPLY+=($host);
  1262.                fi;
  1263.            done;
  1264.        fi;
  1265.        for ((i=0; i < ${#COMPREPLY[@]}; i++ ))
  1266.        do
  1267.            COMPREPLY[i]=$prefix$user${COMPREPLY[i]}$suffix;
  1268.        done;
  1269.    fi;
  1270.    if [[ ${#config[@]} -gt 0 && -n "$aliases" ]]; then
  1271.        local hosts=$( command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]]\{1,\}\([^#*?%]*\)\(#.*\)\{0,1\}$/\1/p' "${config[@]}" );
  1272.        COMPREPLY+=($( compgen -P "$prefix$user"             -S "$suffix" -W "$hosts" -- "$cur" ));
  1273.    fi;
  1274.    if [[ -n ${COMP_KNOWN_HOSTS_WITH_AVAHI:-} ]] && type avahi-browse &> /dev/null; then
  1275.        COMPREPLY+=($( compgen -P "$prefix$user" -S "$suffix" -W             "$( avahi-browse -cpr _workstation._tcp 2>/dev/null |                 awk -F';' '/^=/ { print $7 }' | sort -u )" -- "$cur" ));
  1276.    fi;
  1277.    COMPREPLY+=($( compgen -W         "$( ruptime 2>/dev/null | awk '!/^ruptime:/ { print $1 }' )"         -- "$cur" ));
  1278.    if [[ -n ${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} ]]; then
  1279.        COMPREPLY+=($( compgen -A hostname -P "$prefix$user" -S "$suffix" -- "$cur" ));
  1280.    fi;
  1281.    if [[ -n $ipv4 ]]; then
  1282.        COMPREPLY=("${COMPREPLY[@]/*:*$suffix/}");
  1283.    fi;
  1284.    if [[ -n $ipv6 ]]; then
  1285.        COMPREPLY=("${COMPREPLY[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}");
  1286.    fi;
  1287.    if [[ -n $ipv4 || -n $ipv6 ]]; then
  1288.        for i in ${!COMPREPLY[@]};
  1289.        do
  1290.            [[ -n ${COMPREPLY[i]} ]] || unset -v COMPREPLY[i];
  1291.        done;
  1292.    fi;
  1293.    __ltrim_colon_completions "$prefix$user$cur"
  1294. }
  1295. _longopt ()
  1296. {
  1297.    local cur prev words cword split;
  1298.    _init_completion -s || return;
  1299.    case "${prev,,}" in
  1300.        --help | --usage | --version)
  1301.            return
  1302.        ;;
  1303.        --*dir*)
  1304.            _filedir -d;
  1305.            return
  1306.        ;;
  1307.        --*file* | --*path*)
  1308.            _filedir;
  1309.            return
  1310.        ;;
  1311.        --+([-a-z0-9_]))
  1312.            local argtype=$( LC_ALL=C $1 --help 2>&1 | command sed -ne                 "s|.*$prev\[\{0,1\}=[<[]\{0,1\}\([-A-Za-z0-9_]\{1,\}\).*|\1|p" );
  1313.            case ${argtype,,} in
  1314.                *dir*)
  1315.                    _filedir -d;
  1316.                    return
  1317.                ;;
  1318.                *file* | *path*)
  1319.                    _filedir;
  1320.                    return
  1321.                ;;
  1322.            esac
  1323.        ;;
  1324.    esac;
  1325.    $split && return;
  1326.    if [[ "$cur" == -* ]]; then
  1327.        COMPREPLY=($( compgen -W "$( LC_ALL=C $1 --help 2>&1 |             command sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\1/p' | sort -u )"             -- "$cur" ));
  1328.        [[ $COMPREPLY == *= ]] && compopt -o nospace;
  1329.    else
  1330.        if [[ "$1" == @(rmdir|chroot) ]]; then
  1331.            _filedir -d;
  1332.        else
  1333.            [[ "$1" == mkdir ]] && compopt -o nospace;
  1334.            _filedir;
  1335.        fi;
  1336.    fi
  1337. }
  1338. _lsvirtualenv_usage ()
  1339. {
  1340.    echo "lsvirtualenv [-blh]";
  1341.    echo "  -b -- brief mode";
  1342.    echo "  -l -- long mode";
  1343.    echo "  -h -- this help message"
  1344. }
  1345. _mac_addresses ()
  1346. {
  1347.    local re='\([A-Fa-f0-9]\{2\}:\)\{5\}[A-Fa-f0-9]\{2\}';
  1348.    local PATH="$PATH:/sbin:/usr/sbin";
  1349.    COMPREPLY+=($(         { LC_ALL=C ifconfig -a || ip link show; } 2>/dev/null | command sed -ne         "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]].*/\1/p" -ne         "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]]*$/\1/p" -ne         "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]].*|\2|p" -ne         "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]]*$|\2|p"
  1350.        ));
  1351.    COMPREPLY+=($( { arp -an || ip neigh show; } 2>/dev/null | command sed -ne         "s/.*[[:space:]]\($re\)[[:space:]].*/\1/p" -ne         "s/.*[[:space:]]\($re\)[[:space:]]*$/\1/p" ));
  1352.    COMPREPLY+=($( command sed -ne         "s/^[[:space:]]*\($re\)[[:space:]].*/\1/p" /etc/ethers 2>/dev/null ));
  1353.    COMPREPLY=($( compgen -W '${COMPREPLY[@]}' -- "$cur" ));
  1354.    __ltrim_colon_completions "$cur"
  1355. }
  1356. _minimal ()
  1357. {
  1358.    local cur prev words cword split;
  1359.    _init_completion -s || return;
  1360.    $split && return;
  1361.    _filedir
  1362. }
  1363. _modules ()
  1364. {
  1365.    local modpath;
  1366.    modpath=/lib/modules/$1;
  1367.    COMPREPLY=($( compgen -W "$( command ls -RL $modpath 2>/dev/null |         command sed -ne 's/^\(.*\)\.k\{0,1\}o\(\.[gx]z\)\{0,1\}$/\1/p' )" -- "$cur" ))
  1368. }
  1369. _ncpus ()
  1370. {
  1371.    local var=NPROCESSORS_ONLN;
  1372.    [[ $OSTYPE == *linux* ]] && var=_$var;
  1373.    local n=$( getconf $var 2>/dev/null );
  1374.    printf %s ${n:-1}
  1375. }
  1376. _parse_help ()
  1377. {
  1378.    eval local cmd=$( quote "$1" );
  1379.    local line;
  1380.    {
  1381.        case $cmd in
  1382.            -)
  1383.                cat
  1384.            ;;
  1385.            *)
  1386.                LC_ALL=C "$( dequote "$cmd" )" ${2:---help} 2>&1
  1387.            ;;
  1388.        esac
  1389.    } | while read -r line; do
  1390.        [[ $line == *([[:blank:]])-* ]] || continue;
  1391.        while [[ $line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do
  1392.            line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"};
  1393.        done;
  1394.        __parse_options "${line// or /, }";
  1395.    done
  1396. }
  1397. _parse_usage ()
  1398. {
  1399.    eval local cmd=$( quote "$1" );
  1400.    local line match option i char;
  1401.    {
  1402.        case $cmd in
  1403.            -)
  1404.                cat
  1405.            ;;
  1406.            *)
  1407.                LC_ALL=C "$( dequote "$cmd" )" ${2:---usage} 2>&1
  1408.            ;;
  1409.        esac
  1410.    } | while read -r line; do
  1411.        while [[ $line =~ \[[[:space:]]*(-[^]]+)[[:space:]]*\] ]]; do
  1412.            match=${BASH_REMATCH[0]};
  1413.            option=${BASH_REMATCH[1]};
  1414.            case $option in
  1415.                -?(\[)+([a-zA-Z0-9?]))
  1416.                    for ((i=1; i < ${#option}; i++ ))
  1417.                    do
  1418.                        char=${option:i:1};
  1419.                        [[ $char != '[' ]] && printf '%s\n' -$char;
  1420.                    done
  1421.                ;;
  1422.                *)
  1423.                    __parse_options "$option"
  1424.                ;;
  1425.            esac;
  1426.            line=${line#*"$match"};
  1427.        done;
  1428.    done
  1429. }
  1430. _pci_ids ()
  1431. {
  1432.    COMPREPLY+=($( compgen -W         "$( PATH="$PATH:/sbin" lspci -n | awk '{print $3}')" -- "$cur" ))
  1433. }
  1434. _pgids ()
  1435. {
  1436.    COMPREPLY=($( compgen -W '$( command ps axo pgid= )' -- "$cur" ))
  1437. }
  1438. _pids ()
  1439. {
  1440.    COMPREPLY=($( compgen -W '$( command ps axo pid= )' -- "$cur" ))
  1441. }
  1442. _pnames ()
  1443. {
  1444.    if [[ "$1" == -s ]]; then
  1445.        COMPREPLY=($( compgen -X '<defunct>'             -W '$( command ps axo comm | command sed -e 1d )' -- "$cur" ));
  1446.    else
  1447.        COMPREPLY=($( compgen -X '<defunct>' -W '$( command ps axo command= | command sed -e \
  1448.            "s/ .*//" -e \
  1449.            "s:.*/::" -e \
  1450.            "s/:$//" -e \
  1451.            "s/^[[(-]//" -e \
  1452.            "s/[])]$//" | sort -u )' -- "$cur" ));
  1453.    fi
  1454. }
  1455. _quote_readline_by_ref ()
  1456. {
  1457.    if [ -z "$1" ]; then
  1458.        printf -v $2 %s "$1";
  1459.    else
  1460.        if [[ $1 == \'* ]]; then
  1461.            printf -v $2 %s "${1:1}";
  1462.        else
  1463.            if [[ $1 == ~* ]]; then
  1464.                printf -v $2 ~%q "${1:1}";
  1465.            else
  1466.                printf -v $2 %q "$1";
  1467.            fi;
  1468.        fi;
  1469.    fi;
  1470.    [[ ${!2} == \$* ]] && eval $2=${!2}
  1471. }
  1472. _realcommand ()
  1473. {
  1474.    type -P "$1" > /dev/null && {
  1475.        if type -p realpath > /dev/null; then
  1476.            realpath "$(type -P "$1")";
  1477.        else
  1478.            if type -p greadlink > /dev/null; then
  1479.                greadlink -f "$(type -P "$1")";
  1480.            else
  1481.                if type -p readlink > /dev/null; then
  1482.                    readlink -f "$(type -P "$1")";
  1483.                else
  1484.                    type -P "$1";
  1485.                fi;
  1486.            fi;
  1487.        fi
  1488.    }
  1489. }
  1490. _rl_enabled ()
  1491. {
  1492.    [[ "$( bind -v )" == *$1+([[:space:]])on* ]]
  1493. }
  1494. _root_command ()
  1495. {
  1496.    local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin;
  1497.    local root_command=$1;
  1498.    _command
  1499. }
  1500. _service ()
  1501. {
  1502.    local cur prev words cword;
  1503.    _init_completion || return;
  1504.    [[ $cword -gt 2 ]] && return;
  1505.    if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then
  1506.        _services;
  1507.        [[ -e /etc/mandrake-release ]] && _xinetd_services;
  1508.    else
  1509.        local sysvdirs;
  1510.        _sysvdirs;
  1511.        COMPREPLY=($( compgen -W '`command sed -e "y/|/ /" \
  1512.            -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
  1513.            ${sysvdirs[0]}/${prev##*/} 2>/dev/null` start stop' -- "$cur" ));
  1514.    fi
  1515. }
  1516. _services ()
  1517. {
  1518.    local sysvdirs;
  1519.    _sysvdirs;
  1520.     local IFS='    
  1521. ' reset=$(shopt -p nullglob);
  1522.    shopt -s nullglob;
  1523.    COMPREPLY=($( printf '%s\n' ${sysvdirs[0]}/!($_backup_glob|functions|README) ));
  1524.    $reset;
  1525.    COMPREPLY+=($( systemctl list-units --full --all 2>/dev/null |         awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }' ));
  1526.    if [[ -x /sbin/upstart-udev-bridge ]]; then
  1527.        COMPREPLY+=($( initctl list 2>/dev/null | cut -d' ' -f1 ));
  1528.    fi;
  1529.    COMPREPLY=($( compgen -W '${COMPREPLY[@]#${sysvdirs[0]}/}' -- "$cur" ))
  1530. }
  1531. _shells ()
  1532. {
  1533.    local shell rest;
  1534.    while read -r shell rest; do
  1535.        [[ $shell == /* && $shell == "$cur"* ]] && COMPREPLY+=($shell);
  1536.    done 2> /dev/null < /etc/shells
  1537. }
  1538. _signals ()
  1539. {
  1540.    local -a sigs=($( compgen -P "$1" -A signal "SIG${cur#$1}" ));
  1541.    COMPREPLY+=("${sigs[@]/#${1}SIG/${1}}")
  1542. }
  1543. _split_longopt ()
  1544. {
  1545.    if [[ "$cur" == --?*=* ]]; then
  1546.        prev="${cur%%?(\\)=*}";
  1547.        cur="${cur#*=}";
  1548.        return 0;
  1549.    fi;
  1550.    return 1
  1551. }
  1552. _sysvdirs ()
  1553. {
  1554.    sysvdirs=();
  1555.    [[ -d /etc/rc.d/init.d ]] && sysvdirs+=(/etc/rc.d/init.d);
  1556.    [[ -d /etc/init.d ]] && sysvdirs+=(/etc/init.d);
  1557.    [[ -f /etc/slackware-version ]] && sysvdirs=(/etc/rc.d)
  1558. }
  1559. _terms ()
  1560. {
  1561.    COMPREPLY+=($( compgen -W         "$( command sed -ne 's/^\([^[:space:]#|]\{2,\}\)|.*/\1/p' /etc/termcap             2>/dev/null )" -- "$cur" ));
  1562.    COMPREPLY+=($( compgen -W "$( { toe -a 2>/dev/null || toe 2>/dev/null; }         | awk '{ print $1 }' | sort -u )" -- "$cur" ))
  1563. }
  1564. _tilde ()
  1565. {
  1566.    local result=0;
  1567.    if [[ $1 == \~* && $1 != */* ]]; then
  1568.        COMPREPLY=($( compgen -P '~' -u -- "${1#\~}" ));
  1569.        result=${#COMPREPLY[@]};
  1570.        [[ $result -gt 0 ]] && compopt -o filenames 2> /dev/null;
  1571.    fi;
  1572.    return $result
  1573. }
  1574. _uids ()
  1575. {
  1576.    if type getent &> /dev/null; then
  1577.        COMPREPLY=($( compgen -W '$( getent passwd | cut -d: -f3 )' -- "$cur" ));
  1578.    else
  1579.        if type perl &> /dev/null; then
  1580.            COMPREPLY=($( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- "$cur" ));
  1581.        else
  1582.            COMPREPLY=($( compgen -W '$( cut -d: -f3 /etc/passwd )' -- "$cur" ));
  1583.        fi;
  1584.    fi
  1585. }
  1586. _upvar ()
  1587. {
  1588.    if unset -v "$1"; then
  1589.        if (( $# == 2 )); then
  1590.            eval $1=\"\$2\";
  1591.        else
  1592.            eval $1=\(\"\${@:2}\"\);
  1593.        fi;
  1594.    fi
  1595. }
  1596. _upvars ()
  1597. {
  1598.    if ! (( $# )); then
  1599.        echo "${FUNCNAME[0]}: usage: ${FUNCNAME[0]} [-v varname" "value] | [-aN varname [value ...]] ..." 1>&2;
  1600.        return 2;
  1601.    fi;
  1602.    while (( $# )); do
  1603.        case $1 in
  1604.            -a*)
  1605.                [[ -n ${1#-a} ]] || {
  1606.                    echo "bash: ${FUNCNAME[0]}: \`$1': missing" "number specifier" 1>&2;
  1607.                     return 1
  1608.                 };
  1609.                 printf %d "${1#-a}" &> /dev/null || {
  1610.                     echo "bash:" "${FUNCNAME[0]}: \`$1': invalid number specifier" 1>&2;
  1611.                    return 1
  1612.                };
  1613.                [[ -n "$2" ]] && unset -v "$2" && eval $2=\(\"\${@:3:${1#-a}}\"\) && shift $((${1#-a} + 2)) || {
  1614.                    echo "bash: ${FUNCNAME[0]}:" "\`$1${2+ }$2': missing argument(s)" 1>&2;
  1615.                     return 1
  1616.                 }
  1617.             ;;
  1618.             -v)
  1619.                 [[ -n "$2" ]] && unset -v "$2" && eval $2=\"\$3\" && shift 3 || {
  1620.                     echo "bash: ${FUNCNAME[0]}: $1: missing" "argument(s)" 1>&2;
  1621.                     return 1
  1622.                 }
  1623.             ;;
  1624.             *)
  1625.                 echo "bash: ${FUNCNAME[0]}: $1: invalid option" 1>&2;
  1626.                 return 1
  1627.             ;;
  1628.         esac;
  1629.     done
  1630. }
  1631. _usb_ids ()
  1632. {
  1633.     COMPREPLY+=($( compgen -W         "$( PATH="$PATH:/sbin" lsusb | awk '{print $6}' )" -- "$cur" ))
  1634. }
  1635. _user_at_host ()
  1636. {
  1637.     local cur prev words cword;
  1638.     _init_completion -n : || return;
  1639.     if [[ $cur == *@* ]]; then
  1640.         _known_hosts_real "$cur";
  1641.     else
  1642.         COMPREPLY=($( compgen -u -S @ -- "$cur" ));
  1643.         compopt -o nospace;
  1644.     fi
  1645. }
  1646. _usergroup ()
  1647. {
  1648.     if [[ $cur == *\\\\* || $cur == *:*:* ]]; then
  1649.         return;
  1650.     else
  1651.         if [[ $cur == *\\:* ]]; then
  1652.             local prefix;
  1653.             prefix=${cur%%*([^:])};
  1654.             prefix=${prefix//\\};
  1655.             local mycur="${cur#*[:]}";
  1656.             if [[ $1 == -u ]]; then
  1657.                 _allowed_groups "$mycur";
  1658.             else
  1659.                 local IFS='
  1660. ';
  1661.                 COMPREPLY=($( compgen -g -- "$mycur" ));
  1662.             fi;
  1663.             COMPREPLY=($( compgen -P "$prefix" -W "${COMPREPLY[@]}" ));
  1664.         else
  1665.             if [[ $cur == *:* ]]; then
  1666.                 local mycur="${cur#*:}";
  1667.                 if [[ $1 == -u ]]; then
  1668.                     _allowed_groups "$mycur";
  1669.                 else
  1670.                     local IFS='
  1671. ';
  1672.                     COMPREPLY=($( compgen -g -- "$mycur" ));
  1673.                 fi;
  1674.             else
  1675.                 if [[ $1 == -u ]]; then
  1676.                     _allowed_users "$cur";
  1677.                 else
  1678.                     local IFS='
  1679. ';
  1680.                     COMPREPLY=($( compgen -u -- "$cur" ));
  1681.                 fi;
  1682.             fi;
  1683.         fi;
  1684.     fi
  1685. }
  1686. _userland ()
  1687. {
  1688.     local userland=$( uname -s );
  1689.     [[ $userland == @(Linux|GNU/*) ]] && userland=GNU;
  1690.     [[ $userland == $1 ]]
  1691. }
  1692. _variables ()
  1693. {
  1694.     if [[ $cur =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]; then
  1695.         if [[ $cur == \${* ]]; then
  1696.             local arrs vars;
  1697.             vars=($( compgen -A variable -P ${BASH_REMATCH[1]} -S '}' -- ${BASH_REMATCH[3]} )) && arrs=($( compgen -A arrayvar -P ${BASH_REMATCH[1]} -S '[' -- ${BASH_REMATCH[3]} ));
  1698.             if [[ ${#vars[@]} -eq 1 && -n $arrs ]]; then
  1699.                 compopt -o nospace;
  1700.                 COMPREPLY+=(${arrs[*]});
  1701.             else
  1702.                 COMPREPLY+=(${vars[*]});
  1703.             fi;
  1704.         else
  1705.             COMPREPLY+=($( compgen -A variable -P '$' -- "${BASH_REMATCH[3]}" ));
  1706.         fi;
  1707.         return 0;
  1708.     else
  1709.         if [[ $cur =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]; then
  1710.             local IFS='
  1711. ';
  1712.             COMPREPLY+=($( compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")'             -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}" ));
  1713.             if [[ ${BASH_REMATCH[3]} == [@*] ]]; then
  1714.                 COMPREPLY+=("${BASH_REMATCH[1]}${BASH_REMATCH[2]}[${BASH_REMATCH[3]}]}");
  1715.             fi;
  1716.             __ltrim_colon_completions "$cur";
  1717.             return 0;
  1718.         else
  1719.             if [[ $cur =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*\]$ ]]; then
  1720.                 COMPREPLY+=("$cur}");
  1721.                 __ltrim_colon_completions "$cur";
  1722.                 return 0;
  1723.             else
  1724.                 case $prev in
  1725.                     TZ)
  1726.                         cur=/usr/share/zoneinfo/$cur;
  1727.                         _filedir;
  1728.                         for i in ${!COMPREPLY[@]};
  1729.                         do
  1730.                             if [[ ${COMPREPLY[i]} == *.tab ]]; then
  1731.                                 unset 'COMPREPLY[i]';
  1732.                                 continue;
  1733.                             else
  1734.                                 if [[ -d ${COMPREPLY[i]} ]]; then
  1735.                                     COMPREPLY[i]+=/;
  1736.                                     compopt -o nospace;
  1737.                                 fi;
  1738.                             fi;
  1739.                             COMPREPLY[i]=${COMPREPLY[i]#/usr/share/zoneinfo/};
  1740.                         done;
  1741.                         return 0
  1742.                     ;;
  1743.                 esac;
  1744.             fi;
  1745.         fi;
  1746.     fi;
  1747.     return 1
  1748. }
  1749. _virtualenvs ()
  1750. {
  1751.     local cur="${COMP_WORDS[COMP_CWORD]}";
  1752.     COMPREPLY=($(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}))
  1753. }
  1754. _xfunc ()
  1755. {
  1756.     set -- "$@";
  1757.     local srcfile=$1;
  1758.     shift;
  1759.     declare -F $1 &> /dev/null || {
  1760.         __load_completion "$srcfile"
  1761.     };
  1762.     "$@"
  1763. }
  1764. _xinetd_services ()
  1765. {
  1766.     local xinetddir=/etc/xinetd.d;
  1767.     if [[ -d $xinetddir ]]; then
  1768.         local IFS='    
  1769. ' reset=$(shopt -p nullglob);
  1770.         shopt -s nullglob;
  1771.         local -a svcs=($( printf '%s\n' $xinetddir/!($_backup_glob) ));
  1772.         $reset;
  1773.         COMPREPLY+=($( compgen -W '${svcs[@]#$xinetddir/}' -- "$cur" ));
  1774.     fi
  1775. }
  1776. add2virtualenv ()
  1777. {
  1778.     virtualenvwrapper_verify_workon_home || return 1;
  1779.     virtualenvwrapper_verify_active_environment || return 1;
  1780.     site_packages="`virtualenvwrapper_get_site_packages_dir`";
  1781.     if [ ! -d "${site_packages}" ]; then
  1782.         echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" 1>&2;
  1783.         return 1;
  1784.     fi;
  1785.     path_file="$site_packages/_virtualenv_path_extensions.pth";
  1786.     if [ "$*" = "" ]; then
  1787.         echo "Usage: add2virtualenv dir [dir ...]";
  1788.         if [ -f "$path_file" ]; then
  1789.             echo;
  1790.             echo "Existing paths:";
  1791.             cat "$path_file" | grep --color=auto -v "^import";
  1792.         fi;
  1793.         return 1;
  1794.     fi;
  1795.     remove=0;
  1796.     if [ "$1" = "-d" ]; then
  1797.         remove=1;
  1798.         shift;
  1799.     fi;
  1800.     if [ ! -f "$path_file" ]; then
  1801.         echo "import sys; sys.__plen = len(sys.path)" > "$path_file" || return 1;
  1802.         echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file" || return 1;
  1803.     fi;
  1804.     for pydir in "$@";
  1805.     do
  1806.         absolute_path="$(virtualenvwrapper_absolutepath "$pydir")";
  1807.         if [ "$absolute_path" != "$pydir" ]; then
  1808.             echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2;
  1809.         fi;
  1810.         if [ $remove -eq 1 ]; then
  1811.             sed -i.tmp "\:^$absolute_path$: d" "$path_file";
  1812.         else
  1813.             sed -i.tmp '1 a\
  1814. '"$absolute_path"'
  1815. ' "$path_file";
  1816.         fi;
  1817.         rm -f "${path_file}.tmp";
  1818.     done;
  1819.     return 0
  1820. }
  1821. allvirtualenv ()
  1822. {
  1823.     virtualenvwrapper_verify_workon_home || return 1;
  1824.     typeset d;
  1825.     IFS='%';
  1826.     virtualenvwrapper_show_workon_options | while read d; do
  1827.         [ ! -d "$WORKON_HOME/$d" ] && continue;
  1828.         echo "$d";
  1829.         echo "$d" | sed 's/./=/g';
  1830.         ( source "$WORKON_HOME/$d/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate";
  1831.         virtualenvwrapper_cd "$VIRTUAL_ENV";
  1832.         "$@" );
  1833.         echo;
  1834.     done;
  1835.     unset IFS
  1836. }
  1837. cdproject ()
  1838. {
  1839.     virtualenvwrapper_verify_workon_home || return 1;
  1840.     virtualenvwrapper_verify_active_environment || return 1;
  1841.     if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]; then
  1842.         typeset project_dir="$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")";
  1843.         if [ ! -z "$project_dir" ]; then
  1844.             virtualenvwrapper_cd "$project_dir";
  1845.         else
  1846.             echo "Project directory $project_dir does not exist" 1>&2;
  1847.             return 1;
  1848.         fi;
  1849.     else
  1850.         echo "No project set in $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" 1>&2;
  1851.         return 1;
  1852.     fi;
  1853.     return 0
  1854. }
  1855. cdsitepackages ()
  1856. {
  1857.     virtualenvwrapper_verify_workon_home || return 1;
  1858.     virtualenvwrapper_verify_active_environment || return 1;
  1859.     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`";
  1860.     virtualenvwrapper_cd "$site_packages/$1"
  1861. }
  1862. cdvirtualenv ()
  1863. {
  1864.     virtualenvwrapper_verify_workon_home || return 1;
  1865.     virtualenvwrapper_verify_active_environment || return 1;
  1866.     virtualenvwrapper_cd "$VIRTUAL_ENV/$1"
  1867. }
  1868. cpvirtualenv ()
  1869. {
  1870.     virtualenvwrapper_verify_workon_home || return 1;
  1871.     virtualenvwrapper_verify_virtualenv_clone || return 1;
  1872.     typeset src_name="$1";
  1873.     typeset trg_name="$2";
  1874.     typeset src;
  1875.     typeset trg;
  1876.     if [ "$src_name" = "" ]; then
  1877.         echo "Please provide a valid virtualenv to copy.";
  1878.         return 1;
  1879.     else
  1880.         if [ ! -e "$WORKON_HOME/$src_name" ]; then
  1881.             src="$(virtualenvwrapper_expandpath "$src_name")";
  1882.             if [ ! -e "$src" ]; then
  1883.                 echo "Please provide a valid virtualenv to copy.";
  1884.                 return 1;
  1885.             fi;
  1886.             src_name="$(basename "$src")";
  1887.         else
  1888.             src="$WORKON_HOME/$src_name";
  1889.         fi;
  1890.     fi;
  1891.     if [ "$trg_name" = "" ]; then
  1892.         trg="$WORKON_HOME/$src_name";
  1893.         trg_name="$src_name";
  1894.     else
  1895.         trg="$WORKON_HOME/$trg_name";
  1896.     fi;
  1897.     trg="$(virtualenvwrapper_expandpath "$trg")";
  1898.     if [ -e "$trg" ]; then
  1899.         echo "$trg_name virtualenv already exists.";
  1900.         return 1;
  1901.     fi;
  1902.     echo "Copying $src_name as $trg_name...";
  1903.     ( [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT;
  1904.     virtualenvwrapper_cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" "$src" "$trg";
  1905.     [ -d "$trg" ] && virtualenvwrapper_run_hook "pre_cpvirtualenv" "$src" "$trg_name" && virtualenvwrapper_run_hook "pre_mkvirtualenv" "$trg_name" );
  1906.     typeset RC=$?;
  1907.     [ $RC -ne 0 ] && return $RC;
  1908.     [ ! -d "$WORKON_HOME/$trg_name" ] && return 1;
  1909.     workon "$trg_name";
  1910.     virtualenvwrapper_run_hook "post_mkvirtualenv";
  1911.     virtualenvwrapper_run_hook "post_cpvirtualenv"
  1912. }
  1913. dequote ()
  1914. {
  1915.     eval printf %s "$1" 2> /dev/null
  1916. }
  1917. lssitepackages ()
  1918. {
  1919.     virtualenvwrapper_verify_workon_home || return 1;
  1920.     virtualenvwrapper_verify_active_environment || return 1;
  1921.     typeset site_packages="`virtualenvwrapper_get_site_packages_dir`";
  1922.     ls --color=auto $@ "$site_packages";
  1923.     path_file="$site_packages/_virtualenv_path_extensions.pth";
  1924.     if [ -f "$path_file" ]; then
  1925.         echo;
  1926.         echo "_virtualenv_path_extensions.pth:";
  1927.         cat "$path_file";
  1928.     fi
  1929. }
  1930. lsvirtualenv ()
  1931. {
  1932.     typeset long_mode=true;
  1933.     if command -v "getopts" > /dev/null 2>&1; then
  1934.         OPTIND=1;
  1935.         while getopts ":blh" opt "$@"; do
  1936.             case "$opt" in
  1937.                 l)
  1938.                     long_mode=true
  1939.                 ;;
  1940.                 b)
  1941.                     long_mode=false
  1942.                 ;;
  1943.                 h)
  1944.                     _lsvirtualenv_usage;
  1945.                     return 1
  1946.                 ;;
  1947.                 ?)
  1948.                     echo "Invalid option: -$OPTARG" 1>&2;
  1949.                     _lsvirtualenv_usage;
  1950.                     return 1
  1951.                 ;;
  1952.             esac;
  1953.         done;
  1954.     else
  1955.         typeset -a args;
  1956.         args=($(getopt blh "$@"));
  1957.         if [ $? != 0 ]; then
  1958.             _lsvirtualenv_usage;
  1959.             return 1;
  1960.         fi;
  1961.         for opt in $args;
  1962.         do
  1963.             case "$opt" in
  1964.                 -l)
  1965.                     long_mode=true
  1966.                 ;;
  1967.                 -b)
  1968.                     long_mode=false
  1969.                 ;;
  1970.                 -h)
  1971.                     _lsvirtualenv_usage;
  1972.                     return 1
  1973.                 ;;
  1974.             esac;
  1975.         done;
  1976.     fi;
  1977.     if $long_mode; then
  1978.         allvirtualenv showvirtualenv "$env_name";
  1979.     else
  1980.         virtualenvwrapper_show_workon_options;
  1981.     fi
  1982. }
  1983. mkproject ()
  1984. {
  1985.     typeset -a in_args;
  1986.     typeset -a out_args;
  1987.     typeset -i i;
  1988.     typeset tst;
  1989.     typeset a;
  1990.     typeset t;
  1991.     typeset force;
  1992.     typeset templates;
  1993.     in_args=("$@");
  1994.     force=0;
  1995.     if [ -n "$ZSH_VERSION" ]; then
  1996.         i=1;
  1997.         tst="-le";
  1998.     else
  1999.         i=0;
  2000.         tst="-lt";
  2001.     fi;
  2002.     while [ $i $tst $# ]; do
  2003.         a="${in_args[$i]}";
  2004.         case "$a" in
  2005.             -h | --help)
  2006.                 virtualenvwrapper_mkproject_help;
  2007.                 return
  2008.             ;;
  2009.             -f | --force)
  2010.                 force=1
  2011.             ;;
  2012.             -t)
  2013.                 i=$(( $i + 1 ));
  2014.                 templates="$templates ${in_args[$i]}"
  2015.             ;;
  2016.             *)
  2017.                 if [ ${#out_args} -gt 0 ]; then
  2018.                     out_args=("${out_args[@]-}" "$a");
  2019.                 else
  2020.                     out_args=("$a");
  2021.                 fi
  2022.             ;;
  2023.         esac;
  2024.         i=$(( $i + 1 ));
  2025.     done;
  2026.     set -- "${out_args[@]}";
  2027.     eval "typeset envname=\$$#";
  2028.     virtualenvwrapper_verify_project_home || return 1;
  2029.     if [ -d "$PROJECT_HOME/$envname" -a $force -eq 0 ]; then
  2030.         echo "Project $envname already exists." 1>&2;
  2031.         return 1;
  2032.     fi;
  2033.     mkvirtualenv "$@" || return 1;
  2034.     virtualenvwrapper_cd "$PROJECT_HOME";
  2035.     virtualenvwrapper_run_hook "project.pre_mkproject" $envname;
  2036.     echo "Creating $PROJECT_HOME/$envname";
  2037.     mkdir -p "$PROJECT_HOME/$envname";
  2038.     setvirtualenvproject "$VIRTUAL_ENV" "$PROJECT_HOME/$envname";
  2039.     virtualenvwrapper_cd "$PROJECT_HOME/$envname";
  2040.     for t in $templates;
  2041.     do
  2042.         echo;
  2043.         echo "Applying template $t";
  2044.         virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" "$envname" "$PROJECT_HOME/$envname";
  2045.     done;
  2046.     virtualenvwrapper_run_hook "project.post_mkproject"
  2047. }
  2048. mktmpenv ()
  2049. {
  2050.     typeset tmpenvname;
  2051.     typeset RC;
  2052.     typeset -a in_args;
  2053.     typeset -a out_args;
  2054.     in_args=("$@");
  2055.     if [ -n "$ZSH_VERSION" ]; then
  2056.         i=1;
  2057.         tst="-le";
  2058.     else
  2059.         i=0;
  2060.         tst="-lt";
  2061.     fi;
  2062.     typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD;
  2063.     while [ $i $tst $# ]; do
  2064.         a="${in_args[$i]}";
  2065.         case "$a" in
  2066.             -n | --no-cd)
  2067.                 cd_after_activate=0
  2068.             ;;
  2069.             -c | --cd)
  2070.                 cd_after_activate=1
  2071.             ;;
  2072.             *)
  2073.                 if [ ${#out_args} -gt 0 ]; then
  2074.                     out_args=("${out_args[@]-}" "$a");
  2075.                 else
  2076.                     out_args=("$a");
  2077.                 fi
  2078.             ;;
  2079.         esac;
  2080.         i=$(( $i + 1 ));
  2081.     done;
  2082.     set -- "${out_args[@]}";
  2083.     tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid,sys; sys.stdout.write(uuid.uuid4()+"\n")' 2>/dev/null);
  2084.     if [ -z "$tmpenvname" ]; then
  2085.         tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random,sys; sys.stdout.write(hex(random.getrandbits(64))[2:-1]+"\n")' 2>/dev/null);
  2086.     fi;
  2087.     tmpenvname="tmp-$tmpenvname";
  2088.     mkvirtualenv "$@" "$tmpenvname";
  2089.     RC=$?;
  2090.     if [ $RC -ne 0 ]; then
  2091.         return $RC;
  2092.     fi;
  2093.     [ "$cd_after_activate" = "1" ] && cdvirtualenv;
  2094.     echo "This is a temporary environment. It will be deleted when you run 'deactivate'." | tee "$VIRTUAL_ENV/README.tmpenv";
  2095.     cat - >> "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate" <<EOF
  2096. if [ -f "$VIRTUAL_ENV/README.tmpenv" ]
  2097. then
  2098.     echo "Removing temporary environment:" $(basename "$VIRTUAL_ENV")
  2099.     rmvirtualenv $(basename "$VIRTUAL_ENV")
  2100. fi
  2101. EOF
  2102.  
  2103. }
  2104. mkvirtualenv ()
  2105. {
  2106.     typeset -a in_args;
  2107.     typeset -a out_args;
  2108.     typeset -i i;
  2109.     typeset tst;
  2110.     typeset a;
  2111.     typeset envname;
  2112.     typeset requirements;
  2113.     typeset packages;
  2114.     typeset interpreter;
  2115.     typeset project;
  2116.     in_args=("$@");
  2117.     if [ -n "$ZSH_VERSION" ]; then
  2118.         i=1;
  2119.         tst="-le";
  2120.     else
  2121.         i=0;
  2122.         tst="-lt";
  2123.     fi;
  2124.     while [ $i $tst $# ]; do
  2125.         a="${in_args[$i]}";
  2126.         case "$a" in
  2127.             -a)
  2128.                 i=$(( $i + 1 ));
  2129.                 project="${in_args[$i]}";
  2130.                 if [ ! -d "$project" ]; then
  2131.                     echo "Cannot associate project with $project, it is not a directory" 1>&2;
  2132.                     return 1;
  2133.                 fi;
  2134.                 project="$(virtualenvwrapper_absolutepath ${project})"
  2135.             ;;
  2136.             -h | --help)
  2137.                 virtualenvwrapper_mkvirtualenv_help $a;
  2138.                 return
  2139.             ;;
  2140.             -i)
  2141.                 i=$(( $i + 1 ));
  2142.                 packages="$packages ${in_args[$i]}"
  2143.             ;;
  2144.             -p | --python*)
  2145.                 if echo "$a" | grep --color=auto -q "="; then
  2146.                     interpreter="$(echo "$a" | cut -f2 -d=)";
  2147.                 else
  2148.                     i=$(( $i + 1 ));
  2149.                     interpreter="${in_args[$i]}";
  2150.                 fi
  2151.             ;;
  2152.             -r)
  2153.                 i=$(( $i + 1 ));
  2154.                 requirements="${in_args[$i]}";
  2155.                 requirements="$(virtualenvwrapper_expandpath "$requirements")"
  2156.             ;;
  2157.             *)
  2158.                 if [ ${#out_args} -gt 0 ]; then
  2159.                     out_args=("${out_args[@]-}" "$a");
  2160.                 else
  2161.                     out_args=("$a");
  2162.                 fi
  2163.             ;;
  2164.         esac;
  2165.         i=$(( $i + 1 ));
  2166.     done;
  2167.     if [ ! -z $interpreter ]; then
  2168.         out_args=("--python=$interpreter" ${out_args[@]});
  2169.     fi;
  2170.     set -- "${out_args[@]}";
  2171.     eval "envname=\$$#";
  2172.     virtualenvwrapper_verify_workon_home || return 1;
  2173.     virtualenvwrapper_verify_virtualenv || return 1;
  2174.     ( [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT;
  2175.     virtualenvwrapper_cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" && [ -d "$WORKON_HOME/$envname" ] && virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname" );
  2176.     typeset RC=$?;
  2177.     [ $RC -ne 0 ] && return $RC;
  2178.     [ ! -d "$WORKON_HOME/$envname" ] && return 0;
  2179.     if [ ! -z "$project" ]; then
  2180.         setvirtualenvproject "$WORKON_HOME/$envname" "$project";
  2181.         RC=$?;
  2182.         [ $RC -ne 0 ] && return $RC;
  2183.     fi;
  2184.     workon "$envname";
  2185.     if [ ! -z "$requirements" ]; then
  2186.         pip install -r "$requirements";
  2187.     fi;
  2188.     for a in $packages;
  2189.     do
  2190.         pip install $a;
  2191.     done;
  2192.     virtualenvwrapper_run_hook "post_mkvirtualenv"
  2193. }
  2194. quote ()
  2195. {
  2196.     local quoted=${1//\'/\'\\\'\'};
  2197.     printf "'%s'" "$quoted"
  2198. }
  2199. quote_readline ()
  2200. {
  2201.     local quoted;
  2202.     _quote_readline_by_ref "$1" ret;
  2203.     printf %s "$ret"
  2204. }
  2205. rmvirtualenv ()
  2206. {
  2207.     virtualenvwrapper_verify_workon_home || return 1;
  2208.     if [ ${#@} = 0 ]; then
  2209.         echo "Please specify an environment." 1>&2;
  2210.         return 1;
  2211.     fi;
  2212.     typeset env_name;
  2213.     for env_name in "$@";
  2214.     do
  2215.         echo "Removing $env_name...";
  2216.         typeset env_dir="$WORKON_HOME/$env_name";
  2217.         if [ "$VIRTUAL_ENV" = "$env_dir" ]; then
  2218.             echo "ERROR: You cannot remove the active environment ('$env_name')." 1>&2;
  2219.             echo "Either switch to another environment, or run 'deactivate'." 1>&2;
  2220.             return 1;
  2221.         fi;
  2222.         if [ ! -d "$env_dir" ]; then
  2223.             echo "Did not find environment $env_dir to remove." 1>&2;
  2224.         fi;
  2225.         typeset prior_dir="$(pwd)";
  2226.         virtualenvwrapper_cd "$WORKON_HOME";
  2227.         virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name";
  2228.         command \rm -rf "$env_dir";
  2229.         virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name";
  2230.         if [ -d "$prior_dir" ]; then
  2231.             virtualenvwrapper_cd "$prior_dir";
  2232.         fi;
  2233.     done
  2234. }
  2235. setvirtualenvproject ()
  2236. {
  2237.     typeset venv="$1";
  2238.     typeset prj="$2";
  2239.     if [ -z "$venv" ]; then
  2240.         venv="$VIRTUAL_ENV";
  2241.     fi;
  2242.     if [ -z "$prj" ]; then
  2243.         prj="$(pwd)";
  2244.     else
  2245.         prj=$(virtualenvwrapper_absolutepath "${prj}");
  2246.     fi;
  2247.     if [ ! -d "$venv" ]; then
  2248.         venv="$WORKON_HOME/$venv";
  2249.     fi;
  2250.     if [ ! -d "$venv" ]; then
  2251.         echo "No virtualenv $(basename $venv)" 1>&2;
  2252.         return 1;
  2253.     fi;
  2254.     if [ ! -d "$prj" ]; then
  2255.         echo "Cannot associate virtualenv with \"$prj\", it is not a directory" 1>&2;
  2256.         return 1;
  2257.     fi;
  2258.     echo "Setting project for $(basename $venv) to $prj";
  2259.     echo "$prj" > "$venv/$VIRTUALENVWRAPPER_PROJECT_FILENAME"
  2260. }
  2261. showvirtualenv ()
  2262. {
  2263.     typeset env_name="$1";
  2264.     if [ -z "$env_name" ]; then
  2265.         if [ -z "$VIRTUAL_ENV" ]; then
  2266.             echo "showvirtualenv [env]";
  2267.             return 1;
  2268.         fi;
  2269.         env_name=$(basename "$VIRTUAL_ENV");
  2270.     fi;
  2271.     virtualenvwrapper_run_hook "get_env_details" "$env_name";
  2272.     echo
  2273. }
  2274. toggleglobalsitepackages ()
  2275. {
  2276.     virtualenvwrapper_verify_workon_home || return 1;
  2277.     virtualenvwrapper_verify_active_environment || return 1;
  2278.     typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt";
  2279.     if [ -f $no_global_site_packages_file ]; then
  2280.         rm $no_global_site_packages_file;
  2281.         [ "$1" = "-q" ] || echo "Enabled global site-packages";
  2282.     else
  2283.         touch $no_global_site_packages_file;
  2284.         [ "$1" = "-q" ] || echo "Disabled global site-packages";
  2285.     fi
  2286. }
  2287. virtualenvwrapper ()
  2288. {
  2289.     cat <<EOF
  2290.  
  2291. virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
  2292. tool.  The extensions include wrappers for creating and deleting
  2293. virtual environments and otherwise managing your development workflow,
  2294. making it easier to work on more than one project at a time without
  2295. introducing conflicts in their dependencies.
  2296.  
  2297. For more information please refer to the documentation:
  2298.  
  2299.     http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html
  2300.  
  2301. Commands available:
  2302.  
  2303. EOF
  2304.  
  2305.     typeset helpmarker="#:help:"
  2306.     cat "$VIRTUALENVWRAPPER_SCRIPT" | grep --color=auto "^$helpmarker" | sed -e "s/^$helpmarker/  /g" | sort | sed -e 's/$/\''
  2307. /g'
  2308. }
  2309. virtualenvwrapper_absolutepath ()
  2310. {
  2311.     if [ "$1" = "" ]; then
  2312.         return 1;
  2313.     else
  2314.         "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.abspath(\"$1\")+'\n')";
  2315.         return 0;
  2316.     fi
  2317. }
  2318. virtualenvwrapper_cd ()
  2319. {
  2320.     if [ -n "${BASH:-}" ]; then
  2321.         builtin \cd "$@";
  2322.     else
  2323.         if [ -n "${ZSH_VERSION:-}" ]; then
  2324.             builtin \cd -q "$@";
  2325.         else
  2326.             command \cd "$@";
  2327.         fi;
  2328.     fi
  2329. }
  2330. virtualenvwrapper_derive_workon_home ()
  2331. {
  2332.     typeset workon_home_dir="$WORKON_HOME";
  2333.     if [ "$workon_home_dir" = "" ]; then
  2334.         workon_home_dir="$HOME/.virtualenvs";
  2335.     fi;
  2336.     if echo "$workon_home_dir" | ( unset GREP_OPTIONS;
  2337.     command \grep '^[^/~]' > /dev/null ); then
  2338.         workon_home_dir="$HOME/$WORKON_HOME";
  2339.     fi;
  2340.     if echo "$workon_home_dir" | ( unset GREP_OPTIONS;
  2341.     command \egrep '([\$~]|//)' > /dev/null ); then
  2342.         workon_home_dir="$(virtualenvwrapper_expandpath "$workon_home_dir")";
  2343.     fi;
  2344.     echo "$workon_home_dir";
  2345.     return 0
  2346. }
  2347. virtualenvwrapper_expandpath ()
  2348. {
  2349.     if [ "$1" = "" ]; then
  2350.         return 1;
  2351.     else
  2352.         "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')";
  2353.         return 0;
  2354.     fi
  2355. }
  2356. virtualenvwrapper_get_python_version ()
  2357. {
  2358.     "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.
  2359. }
  2360. virtualenvwrapper_get_site_packages_dir ()
  2361. {
  2362.     "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())"
  2363. }
  2364. virtualenvwrapper_initialize ()
  2365. {
  2366.     export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)";
  2367.     virtualenvwrapper_verify_workon_home -q || return 1;
  2368.     if [ "$VIRTUALENVWRAPPER_HOOK_DIR" = "" ]; then
  2369.         VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME";
  2370.     fi;
  2371.     export VIRTUALENVWRAPPER_HOOK_DIR;
  2372.     mkdir -p "$VIRTUALENVWRAPPER_HOOK_DIR";
  2373.     virtualenvwrapper_run_hook "initialize";
  2374.     virtualenvwrapper_setup_tab_completion;
  2375.     return 0
  2376. }
  2377. virtualenvwrapper_mkproject_help ()
  2378. {
  2379.     echo "Usage: mkproject [-f|--force] [-t template] [virtualenv options] project_name";
  2380.     echo;
  2381.     echo "-f, --force    Create the virtualenv even if the project directory";
  2382.     echo "               already exists";
  2383.     echo;
  2384.     echo "Multiple templates may be selected.  They are applied in the order";
  2385.     echo "specified on the command line.";
  2386.     echo;
  2387.     echo "mkvirtualenv help:";
  2388.     echo;
  2389.     mkvirtualenv -h;
  2390.     echo;
  2391.     echo "Available project templates:";
  2392.     echo;
  2393.     "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' -l project.template
  2394. }
  2395. virtualenvwrapper_mktemp ()
  2396. {
  2397.     command \mktemp "$@"
  2398. }
  2399. virtualenvwrapper_mkvirtualenv_help ()
  2400. {
  2401.     echo "Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name";
  2402.     echo;
  2403.     echo " -a project_path";
  2404.     echo;
  2405.     echo "    Provide a full path to a project directory to associate with";
  2406.     echo "    the new environment.";
  2407.     echo;
  2408.     echo " -i package";
  2409.     echo;
  2410.     echo "    Install a package after the environment is created.";
  2411.     echo "    This option may be repeated.";
  2412.     echo;
  2413.     echo " -r requirements_file";
  2414.     echo;
  2415.     echo "    Provide a pip requirements file to install a base set of packages";
  2416.     echo "    into the new environment.";
  2417.     echo;
  2418.     echo 'virtualenv help:';
  2419.     echo;
  2420.     "$VIRTUALENVWRAPPER_VIRTUALENV" $@
  2421. }
  2422. virtualenvwrapper_run_hook ()
  2423. {
  2424.     typeset hook_script;
  2425.     typeset result;
  2426.     hook_script="$(virtualenvwrapper_tempfile ${1}-hook)" || return 1;
  2427.     ( virtualenvwrapper_cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' ${HOOK_VERBOSE_OPTION:-} --script "$hook_script" "$@" );
  2428.     result=$?;
  2429.     if [ $result -eq 0 ]; then
  2430.         if [ ! -f "$hook_script" ]; then
  2431.             echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2;
  2432.             command \rm -f "$hook_script";
  2433.             return 2;
  2434.         fi;
  2435.         source "$hook_script";
  2436.     else
  2437.         if [ "${1}" = "initialize" ]; then
  2438.             cat - 1>&2 <<EOF
  2439. virtualenvwrapper.sh: There was a problem running the initialization hooks.
  2440.  
  2441. If Python could not import the module virtualenvwrapper.hook_loader,
  2442. check that virtualenvwrapper has been installed for
  2443. VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is
  2444. set properly.
  2445. EOF
  2446.  
  2447.         fi;
  2448.     fi
  2449.     command \rm -f "$hook_script";
  2450.     return $result
  2451. }
  2452. virtualenvwrapper_setup_tab_completion ()
  2453. {
  2454.     if [ -n "${BASH:-}" ]; then
  2455.         function _virtualenvs ()
  2456.         {
  2457.             local cur="${COMP_WORDS[COMP_CWORD]}";
  2458.             COMPREPLY=($(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}))
  2459.         };
  2460.         function _cdvirtualenv_complete ()
  2461.         {
  2462.             local cur="$2";
  2463.             COMPREPLY=($(cdvirtualenv && compgen -d -- "${cur}" ))
  2464.         };
  2465.         function _cdsitepackages_complete ()
  2466.         {
  2467.             local cur="$2";
  2468.             COMPREPLY=($(cdsitepackages && compgen -d -- "${cur}" ))
  2469.         };
  2470.         complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv;
  2471.         complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages;
  2472.         complete -o default -o nospace -F _virtualenvs workon;
  2473.         complete -o default -o nospace -F _virtualenvs rmvirtualenv;
  2474.         complete -o default -o nospace -F _virtualenvs cpvirtualenv;
  2475.         complete -o default -o nospace -F _virtualenvs showvirtualenv;
  2476.     else
  2477.         if [ -n "$ZSH_VERSION" ]; then
  2478.             function _virtualenvs ()
  2479.             {
  2480.                 reply=($(virtualenvwrapper_show_workon_options))
  2481.             };
  2482.             function _cdvirtualenv_complete ()
  2483.             {
  2484.                 reply=($(cdvirtualenv && ls -d ${1}*))
  2485.             };
  2486.             function _cdsitepackages_complete ()
  2487.             {
  2488.                 reply=($(cdsitepackages && ls -d ${1}*))
  2489.             };
  2490.             compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv;
  2491.             compctl -K _cdvirtualenv_complete cdvirtualenv;
  2492.             compctl -K _cdsitepackages_complete cdsitepackages;
  2493.         fi;
  2494.     fi
  2495. }
  2496. virtualenvwrapper_show_workon_options ()
  2497. {
  2498.     virtualenvwrapper_verify_workon_home || return 1;
  2499.     ( virtualenvwrapper_cd "$WORKON_HOME" && echo */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate ) 2> /dev/null | command \tr "\n" " " | command \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate |/|g" | command \tr "/" "\n" | command \sed "/^\s*$/d" | ( unset GREP_OPTIONS;
  2500.     command \egrep -v '^\*$' ) 2> /dev/null
  2501. }
  2502. virtualenvwrapper_tempfile ()
  2503. {
  2504.     typeset suffix=${1:-hook};
  2505.     typeset file;
  2506.     file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)";
  2507.     touch "$file";
  2508.     if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ]; then
  2509.         echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2;
  2510.         return 1;
  2511.     fi;
  2512.     echo $file;
  2513.     return 0
  2514. }
  2515. virtualenvwrapper_verify_active_environment ()
  2516. {
  2517.     if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]; then
  2518.         echo "ERROR: no virtualenv active, or active virtualenv is missing" 1>&2;
  2519.         return 1;
  2520.     fi;
  2521.     return 0
  2522. }
  2523. virtualenvwrapper_verify_project_home ()
  2524. {
  2525.     if [ -z "$PROJECT_HOME" ]; then
  2526.         echo "ERROR: Set the PROJECT_HOME shell variable to the name of the directory where projects should be created." 1>&2;
  2527.         return 1;
  2528.     fi;
  2529.     if [ ! -d "$PROJECT_HOME" ]; then
  2530.         [ "$1" != "-q" ] && echo "ERROR: Project directory '$PROJECT_HOME' does not exist.  Create it or set PROJECT_HOME to an existing directory." 1>&2;
  2531.         return 1;
  2532.     fi;
  2533.     return 0
  2534. }
  2535. virtualenvwrapper_verify_resource ()
  2536. {
  2537.     typeset exe_path="$(command \which "$1" | (unset GREP_OPTIONS; command \grep -v "not found"))";
  2538.     if [ "$exe_path" = "" ]; then
  2539.         echo "ERROR: virtualenvwrapper could not find $1 in your path" 1>&2;
  2540.         return 1;
  2541.     fi;
  2542.     if [ ! -e "$exe_path" ]; then
  2543.         echo "ERROR: Found $1 in path as \"$exe_path\" but that does not exist" 1>&2;
  2544.         return 1;
  2545.     fi;
  2546.     return 0
  2547. }
  2548. virtualenvwrapper_verify_virtualenv ()
  2549. {
  2550.     virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV
  2551. }
  2552. virtualenvwrapper_verify_virtualenv_clone ()
  2553. {
  2554.     virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV_CLONE
  2555. }
  2556. virtualenvwrapper_verify_workon_environment ()
  2557. {
  2558.     typeset env_name="$1";
  2559.     if [ ! -d "$WORKON_HOME/$env_name" ]; then
  2560.         echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." 1>&2;
  2561.         return 1;
  2562.     fi;
  2563.     return 0
  2564. }
  2565. virtualenvwrapper_verify_workon_home ()
  2566. {
  2567.     RC=0;
  2568.     if [ ! -d "$WORKON_HOME/" ]; then
  2569.         if [ "$1" != "-q" ]; then
  2570.             echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2;
  2571.         fi;
  2572.         mkdir -p "$WORKON_HOME";
  2573.         RC=$?;
  2574.     fi;
  2575.     return $RC
  2576. }
  2577. virtualenvwrapper_workon_help ()
  2578. {
  2579.     echo "Usage: workon env_name";
  2580.     echo "";
  2581.     echo "           Deactivate any currently activated virtualenv";
  2582.     echo "           and activate the named environment, triggering";
  2583.     echo "           any hooks in the process.";
  2584.     echo "";
  2585.     echo "       workon";
  2586.     echo "";
  2587.     echo "           Print a list of available environments.";
  2588.     echo "           (See also lsvirtualenv -b)";
  2589.     echo "";
  2590.     echo "       workon (-h|--help)";
  2591.     echo "";
  2592.     echo "           Show this help message.";
  2593.     echo "";
  2594.     echo "       workon (-c|--cd) envname";
  2595.     echo "";
  2596.     echo "           After activating the environment, cd to the associated";
  2597.     echo "           project directory if it is set.";
  2598.     echo "";
  2599.     echo "       workon (-n|--no-cd) envname";
  2600.     echo "";
  2601.     echo "           After activating the environment, do not cd to the";
  2602.     echo "           associated project directory.";
  2603.     echo ""
  2604. }
  2605. wipeenv ()
  2606. {
  2607.     virtualenvwrapper_verify_workon_home || return 1;
  2608.     virtualenvwrapper_verify_active_environment || return 1;
  2609.     typeset req_file="$(virtualenvwrapper_tempfile "requirements.txt")";
  2610.     pip freeze | egrep --color=auto -v '(distribute|wsgiref|appdirs|packaging|pyparsing|six)' > "$req_file";
  2611.     if [ -n "$(cat "$req_file")" ]; then
  2612.         echo "Uninstalling packages:";
  2613.         cat "$req_file";
  2614.         echo;
  2615.         pip uninstall -y $(cat "$req_file" | grep -v '^-f' | sed 's/>/=/g' | cut -f1 -d=);
  2616.     else
  2617.         echo "Nothing to remove.";
  2618.     fi;
  2619.     rm -f "$req_file"
  2620. }
  2621. workon ()
  2622. {
  2623.     typeset -a in_args;
  2624.     typeset -a out_args;
  2625.     in_args=("$@");
  2626.     if [ -n "$ZSH_VERSION" ]; then
  2627.         i=1;
  2628.         tst="-le";
  2629.     else
  2630.         i=0;
  2631.         tst="-lt";
  2632.     fi;
  2633.     typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD;
  2634.     while [ $i $tst $# ]; do
  2635.         a="${in_args[$i]}";
  2636.         case "$a" in
  2637.             -h | --help)
  2638.                 virtualenvwrapper_workon_help;
  2639.                 return 0
  2640.             ;;
  2641.             -n | --no-cd)
  2642.                 cd_after_activate=0
  2643.             ;;
  2644.             -c | --cd)
  2645.                 cd_after_activate=1
  2646.             ;;
  2647.             *)
  2648.                 if [ ${#out_args} -gt 0 ]; then
  2649.                     out_args=("${out_args[@]-}" "$a");
  2650.                 else
  2651.                     out_args=("$a");
  2652.                 fi
  2653.             ;;
  2654.         esac;
  2655.         i=$(( $i + 1 ));
  2656.     done;
  2657.     set -- "${out_args[@]}";
  2658.     typeset env_name="$1";
  2659.     if [ "$env_name" = "" ]; then
  2660.         lsvirtualenv -b;
  2661.         return 1;
  2662.     else
  2663.         if [ "$env_name" = "." ]; then
  2664.             IFS='%';
  2665.             env_name="$(basename $(pwd))";
  2666.             unset IFS;
  2667.         fi;
  2668.     fi;
  2669.     virtualenvwrapper_verify_workon_home || return 1;
  2670.     virtualenvwrapper_verify_workon_environment "$env_name" || return 1;
  2671.     activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate";
  2672.     if [ ! -f "$activate" ]; then
  2673.         echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." 1>&2;
  2674.         return 1;
  2675.     fi;
  2676.     type deactivate > /dev/null 2>&1;
  2677.     if [ $? -eq 0 ]; then
  2678.         typeset -f deactivate | grep --color=auto 'typeset env_postdeactivate_hook' > /dev/null 2>&1;
  2679.         if [ $? -eq 0 ]; then
  2680.             deactivate;
  2681.             unset -f deactivate > /dev/null 2>&1;
  2682.         fi;
  2683.     fi;
  2684.     virtualenvwrapper_run_hook "pre_activate" "$env_name";
  2685.     source "$activate";
  2686.     virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'`;
  2687.     eval "$virtualenvwrapper_original_deactivate";
  2688.     unset -f deactivate > /dev/null 2>&1;
  2689.     eval 'deactivate () {
  2690.        typeset env_postdeactivate_hook
  2691.        typeset old_env
  2692.  
  2693.        # Call the local hook before the global so we can undo
  2694.        # any settings made by the local postactivate first.
  2695.        virtualenvwrapper_run_hook "pre_deactivate"
  2696.  
  2697.        env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
  2698.        old_env=$(basename "$VIRTUAL_ENV")
  2699.  
  2700.        # Call the original function.
  2701.        virtualenv_deactivate $1
  2702.  
  2703.        virtualenvwrapper_run_hook "post_deactivate" "$old_env"
  2704.  
  2705.        if [ ! "$1" = "nondestructive" ]
  2706.        then
  2707.            # Remove this function
  2708.            unset -f virtualenv_deactivate >/dev/null 2>&1
  2709.            unset -f deactivate >/dev/null 2>&1
  2710.        fi
  2711.  
  2712.    }';
  2713.     VIRTUALENVWRAPPER_PROJECT_CD=$cd_after_activate virtualenvwrapper_run_hook "post_activate";
  2714.     return 0
  2715. }
Advertisement
Add Comment
Please, Sign In to add comment