1
0
Fork 0
dotfiles/bash/functions.sh

75 lines
1.6 KiB
Bash
Raw Normal View History

2017-03-10 10:42:12 +00:00
function reload {
2020-09-12 07:58:04 +00:00
source $HOME/.bashrc
2017-03-10 10:42:12 +00:00
}
2024-02-04 10:28:19 +00:00
function __path_list {
IFS=':' read -ra ARY <<< "$PATH"
for DIR in "${ARY[@]}"; do
echo $DIR
done
}
function __path_append {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="${PATH:+"$PATH:"}$1"
fi
}
function __path_prepend {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$1${PATH:+":$PATH"}"
fi
}
2020-09-12 07:58:04 +00:00
# Count lines of code in files that are checked into the current Git repository
2017-10-20 22:58:04 +00:00
function gkloc {
2017-10-20 22:55:39 +00:00
cloc $(git ls-files)
}
2017-03-10 10:42:12 +00:00
function shuf {
awk 'BEGIN {srand(); OFMT="%.17f"} {print rand(), $0}' "$@" | \
sort -k1,1n | \
cut -d' ' -f2-
}
2020-09-12 07:58:04 +00:00
function __window_title {
echo -ne "\033]0;$1\007"
}
2017-03-10 10:42:12 +00:00
function __bash_ssh_complete {
2019-10-09 22:55:27 +00:00
__bash_complete "$(cat $HOME/.ssh/known_hosts | cut -d' ' -f1 | cut -d, -f1)"
2017-03-10 10:42:12 +00:00
}
complete -F __bash_ssh_complete ssh
#
# Directory shortcuts
#
function h { cd $HOME/$1; }
function _h { __bash_directory_complete $HOME; }
complete -F _h h
2024-02-04 10:28:19 +00:00
function c { cd $(realpath $WORK_PROJECTS/$1); }
function _c { __bash_directory_complete $WORK_PROJECTS; }
2017-03-10 10:42:12 +00:00
complete -F _c c
2024-02-04 10:28:19 +00:00
function p { cd $(realpath $PROJECTS/$1); }
function _p { __bash_directory_complete $PROJECTS; }
complete -F _p p
# function cg { cd $GOPATH/src/github.com/$1; }
# function _cg { __bash_directory_complete $GOPATH/src/github.com; }
# complete -W "$(dir -d $HOME/go/path/src/github.com/*/* | cut -d'/' -f8-)" cg
2017-10-05 11:19:48 +00:00
2019-10-09 22:55:27 +00:00
#
# Misc
#
2017-03-10 10:42:12 +00:00
function __bash_directory_complete {
2019-10-09 22:55:27 +00:00
__bash_complete "$(ls $1)"
}
function __bash_complete {
2020-09-12 07:58:04 +00:00
COMPREPLY=($(compgen -o nospace -W "$1" -- ${COMP_WORDS[COMP_CWORD]}))
2017-03-10 10:42:12 +00:00
}