summaryrefslogtreecommitdiff
path: root/modules/common/shell/functions.bash
blob: f354adb680e47526a7308676df6f61b221018cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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"
}