X-Git-Url: https://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=5f8864e6f70d2d8efff60dc5c1f7fcc83b89b6be;hb=30fc297933f590166377f2c583672832c7d25276;hp=21db9e76300642d692d778e6d4e7a80d9134e65a;hpb=1d7346704e49fa779ffccfc2eda2dc12e1937a6f;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 21db9e7..5f8864e 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -113,6 +113,11 @@ fi # check for version/system # check for versions (compatibility reasons) +function is51 () { + [[ $ZSH_VERSION == 5.<1->* ]] && return 0 + return 1 +} + function is4 () { [[ $ZSH_VERSION == <4->* ]] && return 0 return 1 @@ -837,8 +842,18 @@ function grmlcomp () { _ssh_hosts=() _etc_hosts=() fi + + local localname + if check_com hostname ; then + localname=$(hostname) + elif check_com hostnamectl ; then + localname=$(hostnamectl --static) + else + localname="$(uname -n)" + fi + hosts=( - $(hostname) + "${localname}" "$_ssh_config_hosts[@]" "$_ssh_hosts[@]" "$_etc_hosts[@]" @@ -895,7 +910,7 @@ zle -N end-of-somewhere beginning-or-end-of-somewhere # add a command line to the shells history without executing it function commit-to-history () { - print -s ${(z)BUFFER} + print -rs ${(z)BUFFER} zle send-break } zle -N commit-to-history @@ -1574,7 +1589,13 @@ zrcautoload zed # else # print 'Notice: no url-quote-magic available :(' # fi -alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic' +if is51 ; then + # url-quote doesn't work without bracketed-paste-magic since Zsh 5.1 + alias url-quote='autoload -U bracketed-paste-magic url-quote-magic; + zle -N bracketed-paste bracketed-paste-magic; zle -N self-insert url-quote-magic' +else + alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic' +fi #m# k ESC-h Call \kbd{run-help} for the 1st word on the command line alias run-help >&/dev/null && unalias run-help @@ -1856,7 +1877,7 @@ done function batterydarwin () { GRML_BATTERY_LEVEL='' local -a table -table=( ${$(pmset -g ps)[(w)7,8]%%(\%|);} ) +table=( ${$(pmset -g ps)[(w)8,9]%%(\%|);} ) if [[ -n $table[2] ]] ; then case $table[2] in charging) @@ -2269,6 +2290,7 @@ grml_theme_add_token: Token `%s'\'' exists! Giving up!\n\n' $name return 2 fi if (( init )); then + REPLY='' $token $name token=$REPLY fi @@ -2314,6 +2336,7 @@ function grml_prompt_addto () { zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" token new \ || new=${grml_prompt_token_default[$it]} if (( ${+grml_prompt_token_function[$it]} )); then + REPLY='' ${grml_prompt_token_function[$it]} $it else case $it in @@ -2507,8 +2530,17 @@ function grml_vcs_to_screen_title () { } function grml_maintain_name () { - # set hostname if not running on host with name 'grml' - if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then + local localname + if check_com hostname ; then + localname=$(hostname) + elif check_com hostnamectl ; then + localname=$(hostnamectl --static) + else + localname="$(uname -n)" + fi + + # set hostname if not running on local machine + if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != "${localname}" ]] ; then NAME="@$HOSTNAME" fi } @@ -2525,7 +2557,7 @@ function grml_cmd_to_screen_title () { function grml_control_xterm_title () { case $TERM in (xterm*|rxvt*) - set_title "${(%):-"%n@%m:"}" "$1" + set_title "${(%):-"%n@%m:"}" "$2" ;; esac } @@ -2926,9 +2958,6 @@ function sll () { return ${RTN} } -# TODO: Is it supported to use pager settings like this? -# PAGER='less -Mr' - If so, the use of $PAGER here needs fixing -# with respect to wordsplitting. (ie. ${=PAGER}) if check_com -c $PAGER ; then #f3# View Debian's changelog of given package(s) function dchange () { @@ -2936,13 +2965,28 @@ if check_com -c $PAGER ; then [[ -z "$1" ]] && printf 'Usage: %s \n' "$0" && return 1 local package + + # `less` as $PAGER without e.g. `|lesspipe %s` inside $LESSOPEN can't properly + # read *.gz files, try to detect this to use vi instead iff available + local viewer + + if [[ ${$(typeset -p PAGER)[2]} = -a ]] ; then + viewer=($PAGER) # support PAGER=(less -Mr) but leave array untouched + else + viewer=(${=PAGER}) # support PAGER='less -Mr' + fi + + if [[ ${viewer[1]:t} = less ]] && [[ -z "${LESSOPEN}" ]] && check_com vi ; then + viewer='vi' + fi + for package in "$@" ; do if [[ -r /usr/share/doc/${package}/changelog.Debian.gz ]] ; then - $PAGER /usr/share/doc/${package}/changelog.Debian.gz + $viewer /usr/share/doc/${package}/changelog.Debian.gz elif [[ -r /usr/share/doc/${package}/changelog.gz ]] ; then - $PAGER /usr/share/doc/${package}/changelog.gz + $viewer /usr/share/doc/${package}/changelog.gz elif [[ -r /usr/share/doc/${package}/changelog ]] ; then - $PAGER /usr/share/doc/${package}/changelog + $viewer /usr/share/doc/${package}/changelog else if check_com -c aptitude ; then echo "No changelog for package $package found, using aptitude to retrieve it." @@ -3461,6 +3505,11 @@ function simple-extract () { USES_STDIN=true USES_STDOUT=false ;; + *tar.zst) + DECOMP_CMD="tar --zstd -xvf -" + USES_STDIN=true + USES_STDOUT=false + ;; *tar) DECOMP_CMD="tar -xvf -" USES_STDIN=true @@ -3506,6 +3555,11 @@ function simple-extract () { USES_STDIN=true USES_STDOUT=true ;; + *zst) + DECOMP_CMD="zstd -d -c -" + USES_STDIN=true + USES_STDOUT=true + ;; *) print "ERROR: '$ARCHIVE' has unrecognized archive type." >&2 RC=$((RC+1))