summaryrefslogtreecommitdiff
path: root/modules/common/shell/functions.bash
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2024-04-21 02:15:42 +0300
committerAzat Bahawi <azat@bahawi.net>2024-04-21 02:15:42 +0300
commite6ed60548397627bf10f561f9438201dbba0a36e (patch)
treef9a84c5957d2cc4fcd148065ee9365a0c851ae1c /modules/common/shell/functions.bash
parent9ac64328603d44bd272175942d3ea3eaadcabd04 (diff)
2024-04-21
Diffstat (limited to 'modules/common/shell/functions.bash')
-rw-r--r--modules/common/shell/functions.bash59
1 files changed, 59 insertions, 0 deletions
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"
+}