Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A function to help with creating directory aliases and providing
- # completion for them.
- # Taken from here:
- # http://blog.caioromao.com/2010/10/10/Custom-directory-completion.html
- # Tweaked to work with more than just 'cd'
- _make_dir_complete() {
- local aliasname=$1
- local prgname="__s_${aliasname}__"
- cd "$3" >/dev/null 2>&1
- local dirname=$(pwd -L)
- local realpath=$(pwd -P)
- cd - >/dev/null 2>&1
- FUNC="function $prgname() {
- local cur len wrkdir;
- local IFS=$'\n'
- wrkdir="$realpath"
- cur=${COMP_WORDS[COMP_CWORD]};
- len=$((${#wrkdir} + 2));
- COMPREPLY=( $(compgen -S/ -d $wrkdir/$cur| cut -b $len-) );
- }"
- ALIAS="$aliasname () { $2 "$dirname/$*"; }"
- eval $FUNC
- eval $ALIAS
- complete -o nospace -F $prgname $aliasname
- }
- test -e ~/projects &&
- _make_dir_complete cdp cd ~/projects &&
- _make_dir_complete pdp pushd ~/projects
- alias re='cd /home/terdon/research/'
- alias foo='echo /path/to/bar'
- $ ls `foo`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement