about summary refs log tree commit diff stats
path: root/bash
diff options
context:
space:
mode:
authorCase Duckworth2022-07-29 17:04:24 -0500
committerCase Duckworth2022-07-29 17:04:24 -0500
commite6c35b7b14ba815b82a7377f16b06801d68700ce (patch)
tree4f8bee7f6d54e9641a5fb1a6cd5a40cadd944d54 /bash
parentUpdate link (diff)
downloadetc-e6c35b7b14ba815b82a7377f16b06801d68700ce.tar.gz
etc-e6c35b7b14ba815b82a7377f16b06801d68700ce.zip
bleh
Diffstat (limited to 'bash')
-rw-r--r--bash/aliases.bash6
-rw-r--r--bash/functions.bash81
2 files changed, 55 insertions, 32 deletions
diff --git a/bash/aliases.bash b/bash/aliases.bash index 7875574..7b5ed55 100644 --- a/bash/aliases.bash +++ b/bash/aliases.bash
@@ -27,3 +27,9 @@ alias rebash='source ~/.bash_profile'
27 27
28# Debugging 28# Debugging
29alias emacs_goddamnit='pushd ~/.emacs.d;emacs --debug-init;popd' 29alias emacs_goddamnit='pushd ~/.emacs.d;emacs --debug-init;popd'
30
31# other
32alias radio=radish
33if ! command -v fd >/dev/null 2>&1; then
34 alias fd=fdfind
35fi
diff --git a/bash/functions.bash b/bash/functions.bash index 98872f2..c5bcddb 100644 --- a/bash/functions.bash +++ b/bash/functions.bash
@@ -1,45 +1,62 @@
1# Functions 1# Functions
2 2
3memq() { # memq ITEM ARRAY 3memq() { # memq ITEM ARRAY
4 ## Test whether an ITEM is a member of ARRAY. 4 ## Test whether an ITEM is a member of ARRAY.
5 ## Pass ARRAY as ${ARRAY[@]}. 5 ## Pass ARRAY as ${ARRAY[@]}.
6 local e needle="$1"; shift 6 local e needle="$1"
7 for e; do 7 shift
8 [[ "$e" == "$needle" ]] && { 8 for e; do
9 return 0 9 [[ "$e" == "$needle" ]] && {
10 } 10 return 0
11 done 11 }
12 return 1 12 done
13 return 1
13} 14}
14 15
15rebashrc() { # rebashrc 16rebashrc() { # rebashrc
16 ## Reload ~/.bashrc 17 ## Reload ~/.bashrc
17 printf "Loading ~/.bashrc..." >&2 18 printf "Loading ~/.bashrc..." >&2
18 if source "$HOME/.bashrc"; then 19 if source "$HOME/.bashrc"; then
19 echo "OK." >&2 20 echo "OK." >&2
20 else 21 else
21 echo "ERROR!" >&2 22 echo "ERROR!" >&2
22 fi 23 fi
23} 24}
24 25
25first_which() { # first_which COMMAND... 26first_which() { # first_which COMMAND...
26 ## Return the fully-qualified path of the first COMMAND found in $PATH. 27 ## Return the fully-qualified path of the first COMMAND found in $PATH.
27 while :; do 28 while :; do
28 command -v "$1" && break 29 command -v "$1" && break
29 [ -z "$1" ] && return 1 30 [ -z "$1" ] && return 1
30 shift 31 shift
31 done 32 done
32} 33}
33 34
34please() { # please [COMMAND...] 35please() { # please [COMMAND...]
35 # if run without arguments, run the last command with 'sudo' (aka sudo !!) 36 # if run without arguments, run the last command with 'sudo' (aka sudo !!)
36 # if run WITH arguments, alias as sudo 37 # if run WITH arguments, alias as sudo
37 history -d -1 38 history -d -1
38 if [ -z "$1" ]; then 39 if [ -z "$1" ]; then
39 #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') 40 #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q')
40 set -- $(fc -lnr | sed 1q) 41 set -- $(fc -lnr | sed 1q)
41 fi 42 fi
42 echo >&2 sudo "$@" 43 echo >&2 sudo "$@"
43 history -s sudo "$@" 44 history -s sudo "$@"
44 "${DEBUG:-false}" || sudo "$@" 45 "${DEBUG:-false}" || sudo "$@"
45} 46}
47
48mkcd() {
49 if [ $# -lt 1 ]; then
50 command cd
51 return
52 fi
53 if ! [ -d "$1" ]; then
54 read -p "$1 doesn't exist. Create (Y/n)? " yn
55 case "$yn" in
56 n* | N*) return 1 ;;
57 *) mkdir -p "$1" ;;
58 esac
59 fi
60 command cd "$1"
61}
62alias cd='mkcd '