X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=1b8648d64a5e65c66fcd8066edda0b937ad15114;hp=c41cdd740de318a784a94f53a5089d9bcc3aa6f2;hb=8945506c355c0e705ebe8a8f035a419d9459ca5f;hpb=38316b5764b899a4a60ffdafcfa1b7aec34eaf80 diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index c41cdd7..1b8648d 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -198,6 +198,10 @@ isopenbsd(){ [[ $GRML_OSTYPE == "OpenBSD" ]] } +issolaris(){ + [[ $GRML_OSTYPE == "SunOS" ]] +} + #f1# are we running within an utf environment? isutfenv() { case "$LANG $CHARSET $LANGUAGE" in @@ -354,12 +358,12 @@ ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0} typeset -ga ls_options typeset -ga grep_options if ls --color=auto / >/dev/null 2>&1; then - ls_options=( --color=auto ) + ls_options+=( --color=auto ) elif ls -G / >/dev/null 2>&1; then - ls_options=( -G ) + ls_options+=( -G ) fi if grep --color=auto -q "a" <<< "a" >/dev/null 2>&1; then - grep_options=( --color=auto ) + grep_options+=( --color=auto ) fi # utility functions @@ -414,23 +418,22 @@ 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] \n' + while getopts ":hao" opt; do + case $opt in + o) only=1 ;; + a) multi=1 ;; + h) + printf 'usage: salias [-hoa] \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 ;; + *) salias -h >&2; return 1 ;; esac - shift done + shift "$((OPTIND-1))" if (( ${#argv} > 1 )) ; then printf 'Too many arguments %s\n' "${#argv}" @@ -764,14 +767,17 @@ grmlcomp() { # host completion if is42 ; then + [[ -r ~/.ssh/config ]] && _ssh_config_hosts=(${${${(@M)${(f)"$(<$HOME/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) || _ssh_config_hosts=() [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=() [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$( 0 )) ; then fi } +batteryopenbsd(){ +GRML_BATTERY_LEVEL='' +local bat batfull batwarn batnow num +for num in 0 1 ; do + bat=$(sysctl -n hw.sensors.acpibat${num} 2>/dev/null) + if [[ -n $bat ]]; then + batfull=${"$(sysctl -n hw.sensors.acpibat${num}.amphour0)"%% *} + batwarn=${"$(sysctl -n hw.sensors.acpibat${num}.amphour1)"%% *} + batnow=${"$(sysctl -n hw.sensors.acpibat${num}.amphour3)"%% *} + case "$(sysctl -n hw.sensors.acpibat${num}.raw0)" in + *" discharging"*) + if (( batnow < batwarn )) ; then + GRML_BATTERY_LEVEL+=" !v" + else + GRML_BATTERY_LEVEL+=" v" + fi + ;; + *" charging"*) + GRML_BATTERY_LEVEL+=" ^" + ;; + *) + GRML_BATTERY_LEVEL+=" =" + ;; + esac + GRML_BATTERY_LEVEL+="${$(( 100 * batnow / batfull ))%%.*}%%" + fi +done +} + +batteryfreebsd(){ +GRML_BATTERY_LEVEL='' +local num +local -A table +for num in 0 1 ; do + table=( ${=${${${${${(M)${(f)"$(acpiconf -i $num 2>&1)"}:#(State|Remaining capacity):*}%%( ##|%)}//:[ $'\t']##/@}// /-}//@/ }} ) + if [[ -n $table ]] && [[ $table[State] != "not-present" ]] ; then + case $table[State] in + *discharging*) + if (( $table[Remaining-capacity] < 20 )) ; then + GRML_BATTERY_LEVEL+=" !v" + else + GRML_BATTERY_LEVEL+=" v" + fi + ;; + *charging*) + GRML_BATTERY_LEVEL+=" ^" + ;; + *) + GRML_BATTERY_LEVEL+=" =" + ;; + esac + GRML_BATTERY_LEVEL+="$table[Remaining-capacity]%%" + fi +done +} + +batterydarwin(){ +GRML_BATTERY_LEVEL='' +local -a table +table=( ${$(pmset -g ps)[(w)7,8]%%(\%|);} ) +if [[ -n $table[2] ]] ; then + case $table[2] in + charging) + GRML_BATTERY_LEVEL+=" ^" + ;; + discharging) + if (( $table[1] < 20 )) ; then + GRML_BATTERY_LEVEL+=" !v" + else + GRML_BATTERY_LEVEL+=" v" + fi + ;; + *) + GRML_BATTERY_LEVEL+=" =" + ;; + esac + GRML_BATTERY_LEVEL+="$table[1]%%" +fi +} + # set variable debian_chroot if running in a chroot with /etc/debian_chroot if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then debian_chroot=$(&2; return 1;; + esac + done + shift "$((OPTIND-1))" + if (( keep > 0 )); then + while (( $# > 0 )); do + if islinux || isfreebsd; then + cp $verbose -a "${1%/}" "${1%/}_$current_date" + else + cp $verbose -pR "${1%/}" "${1%/}_$current_date" + fi + (( result += $? )) + shift + done + elif (( move > 0 )); then + while (( $# > 0 )); do + mv $verbose "${1%/}" "${1%/}_$current_date" + (( result += $? )) + shift + done + elif (( clean > 0 )); then + if (( $# > 0 )); then + while (( $# > 0 )); do + rm $verbose -rf "${1%/}"_[0-9](#c4,)-(0[0-9]|1[0-2])-([0-2][0-9]|3[0-1])T([0-1][0-9]|2[0-3])(:[0-5][0-9])(#c2)Z + (( result += $? )) + shift + done + else + if (( all > 0 )); then + rm $verbose -rf *_[0-9](#c4,)-(0[0-9]|1[0-2])-([0-2][0-9]|3[0-1])T([0-1][0-9]|2[0-3])(:[0-5][0-9])(#c2)Z(D) + else + rm $verbose -rf *_[0-9](#c4,)-(0[0-9]|1[0-2])-([0-2][0-9]|3[0-1])T([0-1][0-9]|2[0-3])(:[0-5][0-9])(#c2)Z + fi + (( result += $? )) + fi + fi + return $result } #f5# cd to directoy and list files