Add g command for easier navigation
This commit is contained in:
parent
b306a3fa2d
commit
0f20eff390
3 changed files with 38 additions and 0 deletions
1
bashrc
1
bashrc
|
@ -1,5 +1,6 @@
|
|||
# vim: set noexpandtab :miv #
|
||||
alias gcd="source git-cd"
|
||||
alias g="source cd-improved"
|
||||
alias hello='echo "Hello :)"'
|
||||
alias w='watch -t -d -n 1'
|
||||
alias setclip='xclip -selection c'
|
||||
|
|
21
bin/cd-improved
Normal file
21
bin/cd-improved
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
||||
|
||||
if [ -z "$root" ]
|
||||
then
|
||||
cd $@
|
||||
else
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
cd "$root"
|
||||
else
|
||||
if [ $(echo "$1" | grep '^/') ]
|
||||
then cd "$root"$@
|
||||
else cd $@
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
git rev-parse --show-toplevel >/dev/null 2>&1 \
|
||||
&& prompt gitlong || prompt normal
|
16
completion/bash/g
Normal file
16
completion/bash/g
Normal file
|
@ -0,0 +1,16 @@
|
|||
_g_completion() {
|
||||
root=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
if [ "$root" ]
|
||||
then
|
||||
if echo "$2" | grep '^\/' > /dev/null
|
||||
then
|
||||
dirname=$(dirname "$2foo")
|
||||
regex=$(echo $root | sed 's/\//\\\//g')
|
||||
for dir in $(find $root$dirname -maxdepth 1 -mindepth 1 -type d | sed s'/^'"$regex"'//g' | grep '^'"$2")
|
||||
do COMPREPLY+=("$dir/")
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _g_completion -o bashdefault -o dirnames g
|
Loading…
Reference in a new issue