Created
April 6, 2011 20:01
-
-
Save numbata/906401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ################################################################################ | |
| #################### Directory bookmarks ####################################### | |
| ################################################################################ | |
| touch ~/.dir_bookmarks | |
| source ~/.dir_bookmarks | |
| touch ~/.dir_bookmarks_list | |
| export BOOKMARKS_LIST="`cat ~/.dir_bookmarks_list`" | |
| complete -W "$BOOKMARKS_LIST" g | |
| _dir_var () | |
| { | |
| echo "BOOKMARK_DIR_$1" | |
| } | |
| m () | |
| { | |
| VAR=`_dir_var $1` | |
| export ${VAR}=`pwd` | |
| export BOOKMARKS_LIST=${BOOKMARKS_LIST}" $1" | |
| complete -W "$BOOKMARKS_LIST" g | |
| } | |
| g () | |
| { | |
| VAR=`_dir_var $1` | |
| cd ${!VAR} | |
| } | |
| s () | |
| { | |
| bms=`env | grep BOOKMARK_DIR_` | |
| cfg="" | |
| for i in $bms; do | |
| cfg=${cfg}"export ${i}; " | |
| done | |
| echo $cfg > ~/.dir_bookmarks | |
| echo $BOOKMARKS_LIST | tr -s [:space:] \\n | sort | uniq > ~/.dir_bookmarks_list | |
| } | |
| bmclear () | |
| { | |
| echo "" > ~/.dir_bookmarks | |
| echo "" > ~/.dir_bookmarks_list | |
| } | |
| ################################################################################ | |
| #################### SSH hosts auto-completion ################################# | |
| ################################################################################ | |
| _known_hosts () | |
| { | |
| local known_hosts=`sed 's/[ ,].*//g' .ssh/known_hosts` | |
| local word=${COMP_WORDS[COMP_CWORD]} | |
| COMPREPLY=($(compgen -W "$known_hosts" "$word")) | |
| } | |
| complete -F _known_hosts ssh | |
| ################################################################################ | |
| #################### scp auto-completion ####################################### | |
| ################################################################################ | |
| _scp () | |
| { | |
| local word=${COMP_WORDS[COMP_CWORD]} host fulldir dirs fullpath pre | |
| case $word in | |
| *:*) | |
| local cmd=`echo $1 | sed s/scp/ssh/` | |
| host=`echo $word | sed s/:.*//` | |
| fulldir=`echo $word | sed s/[^:]*://` | |
| fullpath=`echo $fulldir | sed 's/[^\/]*$//'` | |
| pre=`echo $fulldir | sed 's/[^\/]*\///g'` | |
| dirs=`$cmd $host "cd $fullpath && ls"` | |
| COMPREPLY=($(compgen -P "$fullpath" -W "$dirs" "$pre")) | |
| ;; | |
| *) | |
| _known_hosts | |
| ;; | |
| esac | |
| } | |
| complete -o dirnames -o filenames -F _scp scp | |
| ################################################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment