From e6ed60548397627bf10f561f9438201dbba0a36e Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 21 Apr 2024 02:15:42 +0300 Subject: 2024-04-21 --- modules/common/shell/functions.bash | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/common/shell/functions.bash (limited to 'modules/common/shell/functions.bash') diff --git a/modules/common/shell/functions.bash b/modules/common/shell/functions.bash new file mode 100644 index 0000000..f354adb --- /dev/null +++ b/modules/common/shell/functions.bash @@ -0,0 +1,59 @@ +function where() { + local s + s="$(type -P "$1")" + realpath "$s" +} +complete -F _command where + +function what() { + local s + s="$(where "$1")" + printf "%s\n" "${s%/*/*}" +} +complete -F _command what + +function cat() { + if (($# == 1)) && [[ -d $1 ]]; then + ll "$1" + else + command cat "$@" + fi +} + +function cd() { + builtin cd "$@" && + if ((${#FUNCNAME[@]} == 1)); then + ls + fi +} + +function mkcd() { + mkdir -p "$1" && builtin cd "$1" +} + +function mvcd() { + mv -i -- "$PWD" "$1" && builtin cd . +} + +function bak() { + local f + for f; do + cp -ai -- "$f" "$f.bak" + done +} + +function ubak() { + local f + for f; do + [[ $f == *.bak ]] || f="$f.bak" + mv -i -- "$f" "${f%.bak}" + done +} + +function dec2hex() { + printf "0x%X\n" "$1" +} + +function hex2dec() { + printf "%d\n" "0x$1" +} -- cgit v1.2.3