summaryrefslogtreecommitdiff
path: root/modules/common/common/shell/functions.bash
diff options
context:
space:
mode:
Diffstat (limited to 'modules/common/common/shell/functions.bash')
-rw-r--r--modules/common/common/shell/functions.bash73
1 files changed, 73 insertions, 0 deletions
diff --git a/modules/common/common/shell/functions.bash b/modules/common/common/shell/functions.bash
new file mode 100644
index 0000000..c18104f
--- /dev/null
+++ b/modules/common/common/shell/functions.bash
@@ -0,0 +1,73 @@
+_complete_alias() {
+ local alias_name=$1
+ local base_function=$2
+ local function_name=_alias_$alias_name
+ shift 2
+ eval "$function_name() {
+ COMP_WORDS=( ${*@Q} \"\${COMP_WORDS[@]:1}\" )
+ (( COMP_CWORD += $# - 1 ))
+ _completion_loader $1
+ $base_function
+ }"
+ complete -F "$function_name" "$alias_name"
+}
+
+function where() {
+ local s
+ s="$(type -P "$1")"
+ realpath "$s"
+}
+_complete_alias where _complete complete
+
+function what() {
+ local s
+ s="$(where "$1")"
+ printf "%s\n" "${s%/*/*}"
+}
+_complete_alias what _complete complete
+
+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"
+}