Switched to zsh, and now?

rigoletto@

Developer
Hello,

I've just switched to shells/zsh, managed to do the basic configuration and "imported" what I have set in my .tcshrc. Still a working in progress but working fine already, but have some tips (there is too much noise around the interwebs)? :)

Btw, I tried to use THIS plugin by either sourcing it and put into .zshrc but err ... didn't work at all. :confused:

Code:
# ZSH Configuration File
# ---------------------------


# Set **** -------------------------------------------
bindkey -e

autoload -Uz compinit
compinit

zstyle ':completion:*' menu select
zstyle ':completion:*' rehash true


setopt complete_aliases
setopt correct
setopt hist_ignore_dups
setopt noflowcontrol


HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000


# Keybindings ----------------------------------------
bindkey    "^[[7~"        beginning-of-line
bindkey "^[[8~"        end-of-line
bindkey    "\e[2~"        overwrite-mode
bindkey    "\e[3~"        delete-char
bindkey "^[Od"        backward-word
bindkey    "\e[1;5D"    backward-word
bindkey "^[Oc"        forward-word
bindkey    "\e[1;5C"    forward-word
bindkey "^[[A"         history-beginning-search-backward
bindkey "^[[B"        history-beginning-search-forward
bindkey    "\e[5~"        history-search-backward
bindkey    "\e[6~"        history-search-forward
bindkey    "^W"        backward-delete-word


# Aliases --------------------------------------------
alias mv='nocorrect mv'       # no spelling correction on mv
alias cp='nocorrect cp'       # no spelling correction on cp
alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
alias j=jobs
alias pu=pushd
alias po=popd
alias d='dirs -v'
alias h=history
alias grep=egrep
alias ll='ls -l'
alias la='ls -a'
alias tb='nc termbin.com 9999'
alias ssh-add='ssh-add ~/.ssh/{private-id_rsa,freebsd-id_ed25519,lbdm-id_rsa}'


# PROMPT ---------------------------------------------
if [[ $USER == root ]]; then
   PROMPT=""$'\n'"%B%F{blue}%~%f %F{red}%m"$'\n'"❱❱❱%b%f "
else
   PROMPT=""$'\n'"%B%F{red}%~%f %F{blue}%m"$'\n'"❱❱❱%b%f "
fi


function preexec() {
  timer=${timer:-$SECONDS}
}

function precmd() {
  if [ $timer ]; then
    timer_show=$(($SECONDS - $timer))
    export RPROMPT="%B%F{yellow}${timer_show}s %b%f"
    unset timer
  fi
}


# Syntax Highlightng ---------------------------------
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh


# vim: tw=0 fo-=anw
## EOF ##

Thanks!
 
Maybe I should back and give another try to shells/fish. :p
fish is weird and sometimes scripts are not working OK because his syntax it's different from POSIX shells. If you want a syntax like fish just need to install textproc/zsh-syntax-highlighting add the following line in your zshrc: source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh.
Also I've noticed in your config that you have bindkey -e to enable emacs mode on command line thow from your posts you look like a vi/vim ( bindkey -v) user not a emacs user but I could be wrong.
 
My ~/.zshrc is 63 KB (2500 lines), so I'd rather not quote it here completely, but maybe the following small “gems” are useful …
If you don't know what a particular thing does (e.g. cdpath), just look it up in the zshall(1) manual page.
Also, if you have any questions about any of these functions and aliases, feel free to ask.
Code:
cdpath=(. .. ~)

mcd () { mkdir "$@" && cd "${@[-1]}" ;        # shortcut for mkdir + cd
rt () { netstat -Wrnfinet | cut -c1-80 ; }        # print routing tables
rt6 () { netstat -Wrnfinet6 | cut -c1-80 ; }        # ditto for IPv6
lf2crlf () { awk '{printf "%s\r\n", $0}' "$@" ; }
crlf2lf () { cat "$@" | tr -d '\r' ; }

words () { cat "$@" | tr -s ' ' '\n'; }
bytes () { hexdump -ve '1/1 "%02x\n"' "$@" ; }
wdiff () { diff "${@[1,-3]}" =(words "${@[-2]}") =(words "${@[-1]}"); }
bdiff () { diff "${@[1,-3]}" =(bytes "${@[-2]}") =(bytes "${@[-1]}"); }
alias wduff='wdiff -u'
alias bduff='bdiff -u'

_SetFlag ()
{
        if [[ "x$2" == "x-R" || "x$2" == "x-r" ]]; then
                set -- -R "$1" "${@[3,-1]}"
        fi
        chflags "$@"
}
schg ()   { _SetFlag schg   "$@"; }
noschg () { _SetFlag noschg "$@"; }
uchg ()   { _SetFlag uchg   "$@"; }
nouchg () { _SetFlag nouchg "$@"; }

# Convert a GNU info document to a single linear document,
# similar to a standard UNIX manual page:
infoman () {info --subnodes -o - $1 2>/dev/null | less}

alias sucs='sort | uniq -c | sort -n'
alias iso2utf='iconv -f iso8859-15 -t utf-8'
alias utf2iso='iconv -f utf-8 -t iso8859-15'
alias intty='script -qt0 /dev/null'        # execute a command within a (pseudo) tty
alias ..='cd "${PWD:h}"'
alias ...='cd "${PWD:h:h}"'
alias ....='cd "${PWD:h:h:h}"'
alias duff='diff -u'
alias grip='grep -i'
alias egrip='egrep -i'

#   Suffix aliases.
alias -s jpg=xv png=xv ppm=xv pgm=xv pbm=xv gif=xv
alias -s ps=gv
alias -s pdf=xpdf
alias -s mp3='mpg123 -b4000'

#   Global aliases -- Be very careful with these!
alias -g ',,'='2>&1 | less -R'
alias -g //='2>&1 | egrep -i'
 
… and this is one of the larger “gems” that I find quite valuable and use it often.
It simply defines a command + (just the plus sign). When you enter it, it re-executes the previous command, but increments the last number in that command. So, for example, you can type:
Code:
xv image00001.jpg
+
+
+
… and these are the commands that are actually executed:
Code:
xv image00001.jpg
xv image00002.jpg
xv image00003.jpg
xv image00004.jpg
Note that all resulting commands are added to the history as if you had typed them. The + command itself is not added to the history because that would be useless.
Here's the code for your ~/.zshrc:
Code:
#   Repeat the previous command, incrementing
#   the *last* number in the line (assumed to be decimal).
#   The modified command is added to the history.
#   The "+" command itself is *not* added to the history
#   if it is the only command on the line.
function + {
        local CMD="$(fc -ln -1 | awk '{
                L = $0
                if (!(i = match(L, /[0-9]+[^0-9]*$/))) {
                        L = L "1"
                        i = length(L)
                }
                j = match(substr(L, i + 1), /[^0-9]|$/)
                old = substr(L, i, j)
                new = (old + 1) ""
                while (length(new) < length(old))
                        new = "0" new
                print substr(L, 1, i-1) new substr(L, i+j)
        }')"
        print -r -- "$CMD" >/dev/tty    # Display modified command.
        print -rs -- "$CMD"             # Save modified command to history.
        eval "$CMD"
}
zshaddhistory_noplus () {
        if [[ "x$1" == "x+"$'\n' ]]; then
                #   Do *not* use "return 1" because it still leaves the "+"
                #   line in the history buffer (though it is not saved).
                #   Instead, "fc -p /dev/null" will kill this line completely.
                fc -p /dev/null
        fi
}
zshaddhistory_functions=( $zshaddhistory_functions zshaddhistory_noplus )
 
That plugin works after a little tweaking. First you need to install shells/zsh-antigen, then add in your .zshrc: source /usr/local/share/zsh-antigen/antigen.zsh. After that create a path to where you will put your plugin (zsh_command_time).
I have plugins in .zsh folder (.zsh/plugins/). eg. from my .zshrc: source ~/.zsh/plugins/command_time/command-time.plugin.zsh.
Final step: install (type in terminal) antigen bundle popstas/zsh-command-time add those lines from plugin "wiki" in your .zshrc:
Code:
# If command execution time above min. time, plugins will not output time.
ZSH_COMMAND_TIME_MIN_SECONDS=1

# Message to display (set to "" for disable).
ZSH_COMMAND_TIME_MSG="Execution time: %s sec"

# Message color.
ZSH_COMMAND_TIME_COLOR="cyan"
and customize command-time.plugin.zsh if you want.
zsh_command_time.png
 
Some more stuff …
Code:
#   Number lines in reverse.  Overrides nl(1).
nl () {
        local DO_REV=false

        if [[ "x$*" == "x-f" ]]; then
                #   Option -f: force reverse, so it works with pipes, too.
                DO_REV=true
                shift
        elif [[ -t 1 ]]; then
                DO_REV=true
        fi
        if $DO_REV; then
                #   Note that the escape sequences are constructed
                #   so that any following tab characters still work.
                awk '{printf "\x1b[7m%6d \x1b[0;0m %s\n", ++i, $0}' "$@"
        else
                command nl "$@"
        fi
}

#   Remove the current directory and change to its parent.
function rmdir. {
        #   Remove the current directory and change to its parent.

        local DIR ANSWER

        if [[ $# -gt 0 ]]; then
                echo "Usage:  rmdir." >&2
                return 1
        fi

        DIR="$(pwd)"
        if [[ -z "$(/bin/ls -A)" ]]; then
                cd "${DIR%/*}"
                rmdir "$DIR"
        else
                echo "Directory not empty:" >&2
                echo "$DIR" >&2
                echo "Are you sure you want to recursively remove the whole directory" >&2
                echo -n "with all of its contents? [y/n] " >&2
                read ANSWER
                if [[ "$ANSWER" == "y" ]]; then
                        cd "${DIR%/*}"
                        rm -rf "$DIR"
                        echo "Ok." >&2
                else
                        echo "Cancelled." >&2
                fi
        fi
}

#   Execute a command in multiple directories.
#   See the usage message for details.
#
#   This is a shell function instead of a script so that
#   any zsh functions and aliases can be used inside the
#   <command> argument.
fordir ()
{
        local CMD DIR ECODE=0 RESULT QUIET=false

        if [[ $# -gt 0 && "$1" == "-q" ]]; then
                QUIET=true
                shift
        fi

        if [[ $# -gt 0 ]]; then
                if [[ "$1" == "--" ]]; then
                        shift
                elif [[ "$1" != "${1#-}" ]]; then
                        echo "fordir:  Error:  Unknown option \"$1\"." >&2
                        return 1
                fi
        fi

        if [[ $# -lt 2 ]]; then
                echo "Usage:  fordir [-q] '<command>' <dir> [<dir> ...]" >&2
                echo "The <command> must be a single argument, i.e. it should be written in quotes." >&2
                echo "It is executed in the current zsh context, so your functions and aliases work" >&2
                echo "as expected.  The return code is the largest return code of all the commands" >&2
                echo "executed." >&2
                return 1
        fi

        CMD="$1"
        shift

        for DIR in "$@"; do
                if ! $QUIET; then
                        echo "========  $DIR  ========"
                fi
                if [[ ! -d "$DIR" ]]; then
                        echo "fordir:  No such directory: $DIR" >&2
                        RESULT=1
                else
                        (
                                cd -- "$DIR"
                                eval "$CMD" || return $?
                        )
                        RESULT=$?
                fi
                if [[ $RESULT -gt $ECODE ]]; then
                        ECODE=$RESULT
                fi
        done

        return $ECODE
}

#   ``fx'' is a shortcut for ``find | xargs''.  The following are equivalent:
#
#       find [<opts>] <dir> [...] -type f -print0 | xargs -0 <cmd ...>
#       fx [<opts>] [<dir> ...] <cmd ...>
#
#   If no <dir> is given, ``.'' is assumed, so you can simply type
#   ``fx grep foo'', for example.  Aliases can be used (but not
#   shell functions), so if you have an alias grip="grep -i", you
#   can type ``fx grip foo''.  find(1) options such as -d, -s and
#   -x can be specified before the directories.
#
#   If you need to specify more find(1) primaries, you have to
#   terminate them with a double hash, for example:
#
#       fx -name \*.c -- grep include
#
#   is the same as:
#
#       find . -name \*.c -type f -print0 | xargs -0 grep include
#
#   ``dx'' is the same as ``fx'', except it uses ``-type d''.
alias fx="_xx f"
alias dx="_xx d"
_xx ()
{
        setopt localoptions
        unsetopt ksharrays

        local -a findargs
        local i=1
        local need_dot=true
        local ftype="$1"
        shift

        #   Collect find(1) options (-d, -s, -x).
        while [[ $# -gt 0 && "$1" == -* && "$1" != -*[^EHLPdsx]* ]]; do
                findargs[i++]="$1"
                shift
        done

        #   Collect directories.
        while [[ $# -gt 0 && -d "$1" && "$1" != -* ]]; do
                findargs[i++]="$1"
                need_dot=false
                shift
        done
        if $need_dot; then
                findargs[i++]=.
        fi

        #   Are there more find(1) prinaries?  If so, collect until "--".
        if [[ $# -gt 0 && "$1" == -* && "$1" != "--" ]]; then
                #   If the primaries don't begin with "-*" (e.g. "!" or "("),
                #   they must be preceded by a single "-".
                if [[ "$1" == "-" ]]; then
                        shift
                fi
                findargs[i++]="("
                while [[ $# -gt 0 && "$1" != "--" ]]; do
                        findargs[i++]="$1"
                        shift
                done
                findargs[i++]=")"
        fi
        if [[ $# -gt 0 && "$1" == "--" ]]; then
                shift
        fi

        if [[ $# -eq 0 ]]; then
                echo "Usage:  ${ftype}x [<opts>] [<dir> ...] [[-] <primary> ... --] <xargs arguments>" >&2
                return 1
        fi

        local cmd="$1"
        shift
        if ! whence "$cmd" >/dev/null; then
                echo "command not found: $cmd" >&2
                return 1
        fi

        #   The following eval+whence construct enables using aliases.
        find "${findargs[@]}" -type $ftype -print0 \
        | eval xargs -0 `whence "$cmd"` '"$@"'
}

#   The "z" function acts as a command prefix that expands
#   compressed files (via pipes).  If the first argument
#   begins with "|", it is appended as an additional filter
#   after compression.  Examples:
#
#   Print MD5 checksums of uncompressed content:
#      z md5 *.gz
#   Print diff, word by word:
#      z '| tr " " "\n"' diff -u oldfile.gz newfile.gz
z () {
        setopt localoptions
        unsetopt ksharrays

        local i
        local COMPR
        local FILTER=""

        if [[ "${1-}" == "|"* ]]; then
                FILTER="$1"
                shift
        fi
        for (( i = 1 ; i <= $# ; i++ )) do
                case "${argv[i]:e}" in
                        gz|tgz)         COMPR=gzip ;;
                        bz2|tbz)        COMPR=bzip2 ;;
                        xz|txz|lzma)    COMPR=xz ;;
                        *)              COMPR="" ;;
                esac
                if [[ -n "$COMPR" && -f "$argv[i]" ]]; then
                        argv[i]="<($COMPR -dc ${(qq)argv[i]} $FILTER )"
                elif [[ "$argv[i]" == *[^-A-Za-z0-9_./]* ]]; then
                        argv[i]="${(qq)argv[i]}"
                fi
        done
        eval "$@"
}

#   "magic-slash":
#
#   When the user types ``../'', convert every further ``/''
#   to another ``../''.  In other words:
#
#   typed:       result:
#   ..//    -->  ../../
#   ..///   -->  ../../../
#   ..////  -->  ../../../../
magic-slash ()
{
        if [[ "$LBUFFER" == *../ ]]; then
                LBUFFER+=../
                _msg_last_dir "$LBUFFER"
        else
                LBUFFER+=/
                _display_dir_info
        fi
}
zle -N magic-slash
bindkey / magic-slash

#   Calculate an arithmetic expression (using /usr/bin/bc -l)
#   and insert the result at the cursor position.
#   Bound to <Esc> <M>.
user-insert-math-expression ()
{
        setopt localoptions extendedglob
        zle -I
        local X=$(
                stty sane <&2
                read "X?Math expression: " <&2
                echo -E "$X" | bc -l 2>/dev/null
        )
        if [[ $? -ne 0 || -z "$X" ]]; then
                zle beep;
                zle -M "***  Error in math expression!  ***"
        else
                if [[ "$X" == *.* ]]; then      # Decimal point?
                        X="${X%%0#}"    # Remove trailing zeros.
                        if [[ "$X" == .* ]]; then
                                X="0$X" # Add zero before.
                        fi
                fi
                LBUFFER="${LBUFFER}$X"
        fi
}
zle -N user-insert-math-expression
bindkey '^[m' user-insert-math-expression

#   Complete the current word by searching the history for matches.
#   Bound to <Esc> <Esc>. If there are multiple matches, you
#   can go back and forth with <Esc> <Esc> and <Esc> <Del>.
user-magic-history-complete()
{
        setopt localoptions
        unsetopt ksharrays
        local -x PRE="$PREFIX"
        local -x NXT=0

        if [[ -z "$PRE" ]]; then
                if [[ $CURRENT -lt 2 ]]; then
                        set -- $(fc -ln -1)
                        if [[ -n "${1-}" ]]; then
                                compadd -Q -S " " -q -- "$1"
                        fi
                        return
                fi
                PRE="${words[ CURRENT - 1 ]} "
                NXT=1
        fi
        while read LINE; do
                if [[ -n "$LINE" ]]; then
                        compadd -Q -V unsorted -1 -S " " -q -- "$LINE"
                fi
        done <<-EOT
                $(fc -lnr 0 | awk '
                        BEGIN {
                                pre = ENVIRON["PRE"] ""
                                nxt = ENVIRON["NXT"] + 0
                                lpre = length(pre)
                        }
                        {
                                if ((i = index($0, pre)) && (i == 1 || substr($0, i - 1, 1) ~ /[        ]/)) {
                                        x1 = substr($0, i, lpre)
                                        x2 = substr($0, i + lpre)
                                        if (i = match(x2, /[^   ][      ]/))
                                                x2 = substr(x2, 1, i)
                                        if (nxt)
                                                print x2 " "
                                        else
                                                print x1 x2 " "
                                }
                        }
                ')
        EOT
}
zle -C user-magic-history-complete-forw menu-complete user-magic-history-complete
zle -C user-magic-history-complete-back reverse-menu-complete user-magic-history-complete
bindkey '^[^[' user-magic-history-complete-forw
bindkey '^[^H' user-magic-history-complete-back
bindkey '^[^?' user-magic-history-complete-back

#   This is a generic function that binds an informative
#   command to a key sequence.  The output of the command
#   is displayed below the current input line of the shell
#   (which is not modified).
#
#   Syntax:  Make_Display_Cmd [-R] <name> <keys> <command>
#
#   <name> can be anything descriptive and should consist
#          only of letters and digits.
#   <keys> Is a keysequence, using the same syntax as the
#          "bindkey" built-in command.  See zshzle(1).
#   <command> is the shell command to be executed.  Be
#             careful that it doesn't print anything to
#             stderr.  In case of a problem you can call
#             "zle beep" to make a (conditional) beep.
#             Note that you should quote the command if
#             it contains special characters.
#
#   Normally, the output of the command is displayed as-is
#   below the current input line.  The outout can be
#   multiple lines, but should be reasonably short so the
#   terminal does not scroll too far.
#
#   If the -R option is specified, the command is expected
#   to produce a list of words, separated by whitespace,
#   which are arranged into columns, similar to the menu
#   display of filename completion.
Make_Display_Cmd ()
{
        local FL="-M" QU='"'
        if [[ "$1" == "-R" ]]; then
                FL="$1 \"\""
                QU=""
                shift
        fi
        local NM="$1" KY="$2"
        shift 2
        eval "user-display-$NM() { zle $FL $QU\$($*)$QU; }"
        zle -N user-display-$NM
        bindkey "$KY" user-display-$NM
}
#   Examples:
Make_Display_Cmd date   "^[d"   date
Make_Display_Cmd cal    "^[c"   ncal -w
Make_Display_Cmd -R ls  "^[l"   ls -Fb
Make_Display_Cmd where  "^[="   where -- '${${BUFFER%%[         ]*}##*/}' \| expand
 
fish is weird and sometimes scripts are not working OK because his syntax it's different from POSIX shells. If you want a syntax like fish just need to install textproc/zsh-syntax-highlighting add the following line in your zshrc: source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh.
Also I've noticed in your config that you have bindkey -e to enable emacs mode on command line thow from your posts you look like a vi/vim ( bindkey -v) user not a emacs user but I could be wrong.

I will not use shells/zsh to script but Thread 69029/post-414906

I already have textproc/zsh-syntax-highlighting since the beginning, and yes I am a vim user but I just like the vim syntax in vim. :)

I will try to make/reproduce the command-time plugin without using a manager, ever if I need to re-write it down. :D

[EDIT]

I already have a config to display the commnd time in seconds, I would just need to improve it to break to seconds/minutes/hours when necessary.

olli@

That will take some time to acknowledge the whole information you gave me. :D

Thanks!
 
This is my .zshrc with some smol changes I did yesterday.

Code:
# ZSH Configuration File
# ---------------------------


# Set **** -------------------------------------------


setopt appendhistory
setopt complete_aliases
setopt correct
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_verify
setopt inc_append_history
setopt noflowcontrol
setopt notify
setopt share_history

unsetopt auto_menu


autoload -U select-word-style; select-word-style b
zstyle ':zle:*' word-chars "*?_-.[]~"


# History --------------------------------------------
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000


# Completion -----------------------------------------
autoload -Uz compinit
compinit

zstyle ':completion:*' menu select
zstyle ':completion:*' rehash true


# Keymap & Keybindings -------------------------------
bindkey -e

bindkey    "^[[7~"        beginning-of-line
bindkey "^[[8~"        end-of-line
bindkey    "\e[2~"        overwrite-mode
bindkey    "\e[3~"        delete-char
bindkey "^[Od"        backward-word
bindkey    "\e[1;5D"    backward-word
bindkey "^[Oc"        forward-word
bindkey    "\e[1;5C"    forward-word
bindkey "^[[A"         history-beginning-search-backward
bindkey "^[[B"        history-beginning-search-forward
bindkey    "\e[5~"        history-search-backward
bindkey    "\e[6~"        history-search-forward
bindkey    "^W"        backward-delete-word


# Aliases --------------------------------------------
alias mv='nocorrect mv'       # no spelling correction on mv
alias cp='nocorrect cp'       # no spelling correction on cp
alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
alias j=jobs
alias pu=pushd
alias po=popd
alias d='dirs -v'
alias h=history
alias grep=egrep
alias ll='ls -l'
alias la='ls -a'
alias tb='nc termbin.com 9999'
alias ssh-add='ssh-add ~/.ssh/{private-id_rsa,freebsd-id_ed25519}'


# PROMPT ---------------------------------------------
if [[ $USER == root ]]; then
   PROMPT=""$'\n'"%B%F{blue}%~%f %F{red}%m"$'\n'"❱❱❱%b%f "
else
   PROMPT=""$'\n'"%B%F{red}%~%f %F{blue}%m"$'\n'"❱❱❱%b%f "
fi


function preexec() {
  timer=${timer:-$SECONDS}
}

function precmd() {
  if [ $timer ]; then
    timer_show=$(($SECONDS - $timer))
    export RPROMPT="%B%F{yellow}${timer_show}s %b%f"
    unset timer
  fi
}


# Terminal Title -------------------------------------
source $HOME/.config/zsh/termsupport.zsh

# Auto Suggestions -----------------------------------
source $HOME/.config/zsh/zsh-autosuggestions.zsh

# Syntax Highlightng ---------------------------------
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh


# vim: tw=0 fo-=anw
## EOF ##
 
The command time thing works already without installing a manager. :)

Ideas and improvements are welcome!

[EDITED]

Code:
_command_time_preexec() {
   timer=${timer:-$SECONDS}
   ZSH_COMMAND_TIME_MSG=${ZSH_COMMAND_TIME_MSG-"Time: %s"}
   ZSH_COMMAND_TIME_COLOR=${ZSH_COMMAND_TIME_COLOR-"white"}
export ZSH_COMMAND_TIME=""
}

_command_time_precmd() {
   if [[ $timer ]]; then
      timer_show=$(($SECONDS - $timer))
      if [[ -n "$TTY" ]] && [[ $timer_show -ge ${ZSH_COMMAND_TIME_MIN_SECONDS:-5} ]]; then
         export ZSH_COMMAND_TIME="$timer_show"
         if [[ ! -z ${ZSH_COMMAND_TIME_MSG} ]]; then
            zsh_command_time
         fi
      fi
   unset timer
fi
}

zsh_command_time() {
   if [[ -n "$ZSH_COMMAND_TIME" ]]; then
      timer_show=$(printf '%dh:%02dm:%02ds\n' $(($ZSH_COMMAND_TIME/3600)) $(($ZSH_COMMAND_TIME%3600/60)) $(($ZSH_COMMAND_TIME%60)))
      #export RPROMPT="%F{white}${ZSH_COMMAND_TIME_MSG} ${timer_show}%f"
      print -P '%F{$ZSH_COMMAND_TIME_COLOR}`printf "${ZSH_COMMAND_TIME_MSG}\n" "$timer_show"`%f'
   fi
}

precmd_functions+=(_command_time_precmd)
preexec_functions+=(_command_time_preexec)

Changing it again. I realized it was not a good idea to use it to set the RPROMPT because the previous time is not cleared if there is no new time to be displayed.
 
For some reason, zsh in a terminal does not any longer respect Cntl-A as 'position cursor at
start of line' ... I've been testing bindkey examples but hardly none explain what
key precisely, the new bindkey maps to, so I can test a new bindkey setting. which makes
fun times leaning on the left cursor arrow for 20-50 seconds...
 
For some reason, zsh in a terminal does not any longer respect Cntl-A as 'position cursor at
start of line' ... I've been testing bindkey examples but hardly none explain what
key precisely, the new bindkey maps to, so I can test a new bindkey setting. which makes
fun times leaning on the left cursor arrow for 20-50 seconds...

I never use Crtl-A for that but 'Home'; however I tested and it works for me.
 
For some reason, zsh in a terminal does not any longer respect Cntl-A as 'position cursor at
start of line' ... I've been testing bindkey examples but hardly none explain what
key precisely, the new bindkey maps to, so I can test a new bindkey setting. which makes
fun times leaning on the left cursor arrow for 20-50 seconds...

First you need to add zle function in your .zshrc and "enable vi/vim mode" (bindkey -v). With the help of zle-la you can associate any key combination to those widgets.
 
Back
Top