-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc.local.grml
42 lines (37 loc) · 1.23 KB
/
.zshrc.local.grml
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
# some stuff taken from grml by schuett
# creates an alias and precedes the command with
# sudo if $EUID is not zero.
salias() {
emulate -L zsh
local only=0 ; local multi=0
local key val
while [[ $1 == -* ]] ; do
case $1 in
(-o) only=1 ;;
(-a) multi=1 ;;
(--) shift ; break ;;
(-h)
printf 'usage: salias [-h|-o|-a] <alias-expression>\n'
printf ' -h shows this help text.\n'
printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n'
printf ' be careful using this option.\n'
printf ' -o only sets an alias if a preceding sudo would be needed.\n'
return 0
;;
(*) printf "unkown option: '%s'\n" "$1" ; return 1 ;;
esac
shift
done
if (( ${#argv} > 1 )) ; then
printf 'Too many arguments %s\n' "${#argv}"
return 1
fi
key="${1%%\=*}" ; val="${1#*\=}"
if (( EUID == 0 )) && (( only == 0 )); then
alias -- "${key}=${val}"
elif (( EUID > 0 )) ; then
(( multi > 0 )) && val="${val// ; / ; sudo }"
alias -- "${key}=sudo ${val}"
fi
return 0
}