Skip to content

Instantly share code, notes, and snippets.

@apwan
Created July 29, 2019 04:52
Show Gist options
  • Save apwan/f3d4921af65437ca67974fb27f7be787 to your computer and use it in GitHub Desktop.
Save apwan/f3d4921af65437ca67974fb27f7be787 to your computer and use it in GitHub Desktop.
useful shell functions for .bashrc
vicmd() {
[ "$#" -lt 1 ] && echo "Usage: $0 [CMD_name]" >&2 && return 1;
# check alias
#echo "type $(type -t $1)"
[[ "$(type -t $1)" =~ ("alias"|"builtin"|"function") ]] && echo "$1 is $(type -t $1), not a valid cmd! " >&2 && return 1
local CMD_="$(which $1 2>/dev/null)"
[ -x "$CMD_" ] && vi "$CMD_" || vi "$MY_SHARE_HOME/bin/$1"
}
export -f vicmd
cmdir() {
dirname "$(readlink -f $(which $1 2>/dev/null) 2>/dev/null)"
}
export -f cmdir
sumdir() {
du -sh $@;
ls $@ | wc -l;
}
export -f sumdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment