summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2008-09-30 23:10:12 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2008-09-30 23:10:12 +0200
commita0b301c9a97f70a9b42e5d754f2365820899aa70 (patch)
treeb26825c75395976d32f047a8be585cb2d318e840 /etc
parentbe35c378d3f05aa4d8f7366460ba5127539434d7 (diff)
Added salias function from the grml zshrc
Diffstat (limited to 'etc')
-rw-r--r--etc/alias/default4
-rw-r--r--etc/alias/short4
-rw-r--r--etc/function4
-rw-r--r--etc/functions/salias37
4 files changed, 43 insertions, 6 deletions
diff --git a/etc/alias/default b/etc/alias/default
index ccda10c..a728824 100644
--- a/etc/alias/default
+++ b/etc/alias/default
@@ -40,8 +40,8 @@ alias host='host -a'
alias mx='mx -aZ'
# Only TCP/TCP6, not sockets and such
-alias netstat='sudo netstat -atp tcp'
-linux: alias netstat='sudo netstat --program --all --tcp --extend'
+salias netstat='netstat -atp tcp'
+linux: salias netstat='netstat --program --all --tcp --extend'
#
diff --git a/etc/alias/short b/etc/alias/short
index ee4fedb..9c45432 100644
--- a/etc/alias/short
+++ b/etc/alias/short
@@ -62,5 +62,5 @@ alias rd='rmdir'
alias rsync-serve="rsync --daemon --port=10873 --no-detach --config=/dev/stdin --log-file=/dev/stdout -v <<< $'[.]\n\tpath = .\n\tuse chroot = no'"
## Suspend
-alias s2d='sudo s2disk'
-alias s2r='sudo s2ram -f'
+salias s2d='s2disk'
+salias s2r='s2ram -f'
diff --git a/etc/function b/etc/function
index 60d6454..3ee4d4a 100644
--- a/etc/function
+++ b/etc/function
@@ -7,8 +7,8 @@ autoload catch throw
autoload zargs
# own functions
-autoload anytag chpwd dirinfo extr plonkhost put reload rtab world-readable
-autoload xexport xsource youtube-watch
+autoload anytag chpwd dirinfo extr plonkhost put reload rtab salias
+autoload world-readable xexport xsource youtube-watch
colors
chpwd
diff --git a/etc/functions/salias b/etc/functions/salias
new file mode 100644
index 0000000..d8a3340
--- /dev/null
+++ b/etc/functions/salias
@@ -0,0 +1,37 @@
+## vim:ft=zsh
+## creates an alias and precedes the command with sudo if $EUID is not zero.
+## Taken from the grml zshrc - http://grml.org
+local only=0
+local multi=0
+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