diff options
Diffstat (limited to 'bash/functions.bash')
-rw-r--r-- | bash/functions.bash | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bash/functions.bash b/bash/functions.bash index cce92be..98872f2 100644 --- a/bash/functions.bash +++ b/bash/functions.bash | |||
@@ -1,3 +1,5 @@ | |||
1 | # Functions | ||
2 | |||
1 | memq() { # memq ITEM ARRAY | 3 | memq() { # memq ITEM ARRAY |
2 | ## Test whether an ITEM is a member of ARRAY. | 4 | ## Test whether an ITEM is a member of ARRAY. |
3 | ## Pass ARRAY as ${ARRAY[@]}. | 5 | ## Pass ARRAY as ${ARRAY[@]}. |
@@ -28,3 +30,16 @@ first_which() { # first_which COMMAND... | |||
28 | shift | 30 | shift |
29 | done | 31 | done |
30 | } | 32 | } |
33 | |||
34 | please() { # please [COMMAND...] | ||
35 | # if run without arguments, run the last command with 'sudo' (aka sudo !!) | ||
36 | # if run WITH arguments, alias as sudo | ||
37 | history -d -1 | ||
38 | if [ -z "$1" ]; then | ||
39 | #set -- $(HISTTIMEFORMAT=$'\t' history 2 | sed 's/^.*\t//;q') | ||
40 | set -- $(fc -lnr | sed 1q) | ||
41 | fi | ||
42 | echo >&2 sudo "$@" | ||
43 | history -s sudo "$@" | ||
44 | "${DEBUG:-false}" || sudo "$@" | ||
45 | } | ||