Oh-my-zsh/ZSH : Show your work

Hi community, don’t know how many zsh’s users are here. Do you think to share your graphical setup for ZSH shell ?

:wink:

EDIT: forgot my screenshot


powerline9k theme

5 Likes

Nope :wink:

It’s a terminal it is pretty dull :smiley:

3 Likes

i also like a minimalist terminal. there is nothing to see. here is what it looks like after a fresh boot (the top white line is only visible then):

i started to use oh-my-zsh, but later used pure zsh with all the features i used to use in oh-my-zsh plus a lot more stuff. here is my ~/.zshrc file:

## Plugins section:
## ----------------

# Use syntax highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# Use history substring search
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
# bind UP and DOWN arrow keys to substring search
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
bindkey '^[[A' history-substring-search-up			
bindkey '^[[B' history-substring-search-down

## Use autosuggestion
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
export TERM=xterm-256color                                      # schaltet ein thema mit 256 farben für qterminal frei. nur damit funktionieren die cusomizations der farbe!
ZSH_AUTOSUGGESTION_HIGHLIGHT_STYLE='fg=grey'                    # die farbe für autosuggestions funktioniert nur, wenn output of "echotc Co" >= 21 ist. ansonsten sollte "TERM=xterm-256color" exportiert werden !!!
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=50

autoload -U compinit 
# Enable completion system with this command:
compinit -d "$HOME/.zshCompInit"                                # "-d" argument creates a "zcompdump" file, which speeds up the initialization of completion system.
# Completion Styles:
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
zstyle ':completion:*' rehash true                              # automatically find new executables in path
zstyle ':completion:*' menu select								# Completion offers a menu, which can be navigated with arrow keys
# Speed up completions
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
WORDCHARS=${WORDCHARS//\/[&.;]}                                 # Don't consider certain characters part of the word --> easier navigation with  CTRL+ArrowKeys  for autocompletions
# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions'    format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
zstyle ':completion:*:messages'        format '%d'
zstyle ':completion:*:warnings'        format 'No matches for: %d'
zstyle ':completion:*:corrections'     format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
# separate matches into groups
zstyle ':completion:*:matches'         group 'yes'
zstyle ':completion:*'                 group-name ''
zstyle ':completion:*' menu select _complete _ignored _approximate # activate menu for selection
zstyle -e ':completion:*:approximate:'    max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
# Search path for sudo completion
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
                                           /usr/local/bin  \
                                           /usr/sbin       \
                                           /usr/bin        \
                                           /sbin           \
                                           /bin


# run z-git (has to be installed) when zsh starts:
#[ -r /usr/lib/z.sh ] && source /usr/lib/z.sh


## Options section
## ---------------

setopt correct          	                                    # Auto correct mistakes
setopt extended_glob     	                                    # Extended globbing. Allows using regular expressions with *
setopt nocaseglob       	                                    # Case insensitive globbing
setopt autoparamslash                                           # If a parameter is completed whose content is the name of a directory, then add a trailing slash instead of a space
setopt rcexpandparam    	                                    # Array expension with parameters
setopt nocheckjobs      	                                    # Don't warn about running processes when exiting
setopt numericglobsort  	                                    # Sort filenames numerically when it makes sense
setopt nobeep           	                                    # No beep
setopt append_history    	                                    # Immediately append history instead of overwriting
setopt histignorealldups 	                                    # If a new command is a duplicate, remove the older one
setopt share_history                                            # import new commands from the history file also in other zsh-session
setopt histignorespace                                          # remove command lines from the history list when the first character on the line is a space
setopt auto_cd                                                  # if only directory path is entered, cd there.
setopt noshwordsplit                                            # use zsh style word splitting

HISTFILE=~/.zhistory
HISTSIZE=600
SAVEHIST=600
export EDITOR="/usr/bin/nano"                                   # set minimal text editor globally as environment variable.
export VISUAL="/usr/bin/nano"                                   # set full-featured text editor. Mainly for CLI usage.


## Keybindings section
## -------------------

bindkey -e
bindkey '^[[7~' beginning-of-line                               # Home key
bindkey '^[[H' beginning-of-line                                # Home key
if [[ "${terminfo[khome]}" != "" ]]; then
  bindkey "${terminfo[khome]}" beginning-of-line                                              # [Home] - Go to beginning of line
fi
[[ "${terminfo[kend]}" != "" ]] && bindkey "${terminfo[kend]}" end-of-line                    # [End] - Go to end of line
bindkey '^[[2~' overwrite-mode                                  # Insert key
bindkey '^[[3~' delete-char                                     # Delete key
bindkey '^[[C'  forward-char                                    # Right key
bindkey '^[[D'  backward-char                                   # Left key
bindkey '^[[5~' history-beginning-search-backward               # Page up key
bindkey '^[[6~' history-beginning-search-forward                # Page down key

# Navigate words with ctrl+arrow keys
bindkey '^[Oc' forward-word                                     #
bindkey '^[Od' backward-word                                    #
bindkey '^[[1;5D' backward-word                                 #
bindkey '^[[1;5C' forward-word                                  #
bindkey '^H' backward-kill-word                                 # delete previous word with ctrl+backspace
bindkey '^[[Z' undo                                             # Shift+tab undo last action


## Alias section
## -------------

# enter "alias" into your terminal to get a list of all currently active aliases in your session.

alias ls='ls -l -h --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F'
alias la='ls -lA -h --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F'
alias ll='ls -lA -h --group-directories-first --time-style=+"%d.%m.%Y %H:%M" --color=auto -F'
#alias ls='exa -hl --color-scale --group-directories-first --sort name --time-style=long-iso '
alias grep='grep --color=auto -d skip'
alias cp="cp -i"                                                # Confirm before overwriting something
alias df='df -h'                                                # Human-readable sizes
alias free='free -h'                                            # show sizes in human-readable format
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias c='clear'
#alias y='yaourt'
#alias y='pacaur -Ss'
#alias pac='pacaur -Ss'
alias p='pacui'
alias music='play /home/excalibur/Music/Ruhige\ Musik\ +\ Jazz'							# plays my music


function cd {                                                   # execute "ls" after every time the "cd" command is finished. "cd" bringt einen immernoch zurück nach $HOME.
  builtin cd "$@" && ls
}


# extract - archive extractor                                   # command line archive extractor.
# usage: extract <file>
function extract {
  if [ -f $1 ]; then
    case $1 in
      *.tar.bz2|*.tbz2)  tar xjf $1   ;;
      *.tar.gz|*.tgz)    tar xzf $1   ;;
      *.bz2)             bunzip2 $1   ;;
      *.rar)             unrar x $1   ;;
      *.gz)              gunzip $1    ;;
      *.tar)             tar xf $1    ;;
      *.zip)             unzip $1     ;;
      *.Z)               uncompress $1;;
      *.7z)              7z x $1      ;;
      *)                 echo "'$1' cannot be extracted via extract()" && return 1;;
    esac
  else
    echo "'$1' is not a valid file"
    return 1
  fi
}


# display history using fzf. 
# commands can be edited before execution. if commands should be executed immediately, replace "print -z" with "eval".
function history {
  print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf -e -i +s --reverse --tac --margin=4%,1%,1%,2% --inline-info --header="ENTER to select (but not execute) command. ESC or CTRL+C to quit." --prompt='Enter string to filter history > ' | sed 's/ *[0-9]* *//' )
}


# fkill - kill process using fzf.
# more great examples how fzf can be used: https://github.com/junegunn/fzf/wiki/examples
function fkill {
  local pid
  pid=$(ps -ef | sed 1d | fzf -e -m -i +s --reverse --tac --margin=4%,1%,1%,2% --inline-info --header="TAB to (un)select. ENTER to kill selected process(es). ESC or CTRL+C to quit." --prompt='Enter string to filter history > ' | awk '{print $2}')

  if [ "x$pid" != "x" ]
  then
    echo $pid | xargs kill -${1:-9}
  fi
}


# play music in CLI (from specified directory or current directory):
function play {
  if [[ $# == 0 ]]; then
    # find audio files to play in current directory, if no argument it given
    mpv --no-video --shuffle --volume=50 --speed 1 --playlist <(find "$PWD" -type f -follow)
  else
    # find audio files to play in given directory (directory is given as argument)
    mpv --no-video --shuffle --volume=50 --speed 1 --playlist <(find "$@" -type f -follow -exec readlink -f {} \;)
  fi
}


# so that Ctrl-V works
alias xclip='xclip -selection c'
# Defines transfer alias and provides easy command line file and folder sharing. anstelle von transfer.sh würde auch termbin.com oder chunk.io funktionieren.
function transfer { 

  # check, whether "curl" is installed
  curl --version &>/dev/null
  if [ $? -ne 0 ]; then
    echo "Could not find curl."
    return 1
  fi

  # check arguments
  if [ $# -eq 0 ]; then 
    echo "No arguments specified. Usage examples:\ntransfer /tmp/test-file.md\ntransfer /tmp/test-directory\ncat /tmp/test.md | transfer test-pipe.md"
    return 1
  fi

  # get temporarily filename, output is written to this file show progress can be showed
  tmpfile=$( mktemp -t transferXXX )
    
  # upload stdin or file
  file=$1

  if tty -s; then 
    basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g') 

    if [ ! -e $file ]; then
      echo "File $file doesn't exists."
      return 1
    fi
        
    if [ -d $file ]; then
      # zip directory and transfer
      zipfile=$( mktemp -t transferXXX.zip )
      cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
      curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
      rm -f $zipfile
    else
      # transfer file
      curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
    fi
  else 
    # transfer pipe
    curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
  fi
   
  # cat output link
  cat $tmpfile
  
  # copy link to clipboard. Can be pasted with CTRL+V.
  cat $tmpfile | xclip;

  # cleanup
  rm -f $tmpfile
}


## Theming section
## ---------------

autoload -U colors zcalc
# Enable colors in prompt:
colors

# Print a greeting message when shell is started
echo $USER@$HOST $(uname -sr) $(lsb_release -rs)

# enable substitution for prompt
setopt prompt_subst

# Prompt similar to default bash prompt, or redhat zsh prompt with colors
 precmd() { print -rP "%{$fg[cyan]%}------------------------------------------------" }     # first line of left prompt: cyan line
# Prompt similar to default bash prompt, or redhat zsh prompt with colors
 #PROMPT="%{$fg[green]%}[%n@%m %1~]%{$reset_color%}%(!.#.$) "
 PROMPT="%(?.%B%{$fg[cyan]%}%~ >%b.%B%{$fg[red]%}%~ >%b) %{$reset_color%}"                    # second line of left prompt: red when previous command exited with error (this works in git branches, too!)
 

## Right Prompt:
#  - shows status of git when in git repository (code adapted from https://techanic.net/2012/12/30/my_git_prompt_for_zsh.html)
#  - shows exit status of previous command (if previous command finished with an error)
#  - is invisible, if neither is the case
 
# Specify which colors and symbols are used by the git prompt on the right side:
GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"             # A"NUM"         - ahead by "NUM" commits = ready for "git push"
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"           # B"NUM"         - behind by "NUM" commits
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"     # lightning bolt - merge conflict
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}■%{$reset_color%}"       # red circle     - untracked files
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}■%{$reset_color%}"     # yellow circle  - tracked files modified
GIT_PROMPT_STAGED="%{$fg_bold[green]%}■%{$reset_color%}"        # green circle   - staged changes present

function parse_git_branch {
  # Show Git branch/tag, or name-rev if on detached head
  ( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null
}

function parse_git_state {
  # Show different symbols as appropriate for various Git repository states
  
  # First, do a "git fetch". This command fetches information about the online repository and writes it into "git log". We need this information to show how many commits our local repository is ahead/behind the online repo.
  git fetch &> /dev/null
  
  # Compose this value via multiple conditional appends.
  local GIT_STATE=""

  local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
  if [ "$NUM_AHEAD" -gt 0 ]; then
    # append $GIT_PROMPT_AHEAD to the end of $GIT_STATE:
    GIT_STATE="$GIT_STATE ${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}"
  fi

  local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
  if [ "$NUM_BEHIND" -gt 0 ]; then
    GIT_STATE="$GIT_STATE ${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}"
  fi

  local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
  if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
    GIT_STATE="$GIT_STATE $GIT_PROMPT_MERGING"
  fi

  if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
    GIT_STATE="$GIT_STATE $GIT_PROMPT_UNTRACKED"
  fi

  if ! git diff --quiet 2> /dev/null; then
    GIT_STATE="$GIT_STATE $GIT_PROMPT_MODIFIED"
  fi

  if ! git diff --cached --quiet 2> /dev/null; then
    GIT_STATE="$GIT_STATE $GIT_PROMPT_STAGED"
  fi

  if [[ -n $GIT_STATE ]]; then
  	# echo [ $GIT_STATE ]   -- $GIT_STATE can be multiple conditions as defined above
    echo "$GIT_PROMPT_PREFIX$GIT_STATE $GIT_PROMPT_SUFFIX"
  fi
}

function git_prompt_string {
  # $git_where contains the name of git branch i am currently in. Attention: in some cases, "refs/heads/" or "tags/" is in front of the branch name and needs to be removed.
  local git_where="$(parse_git_branch)"
  
  # If inside a Git repository, print its branch and state
  [ -n "$git_where" ] && echo "$(parse_git_state) $GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"

  # if not inside the git repo, print exit codes of last command (only if it failed)
  [ ! -n "$git_where" ] && echo "%{$fg[red]%} %(?..[%?])"
  # Right prompt with exit status of previous command marked with ✓ or ✗
  #RPROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})"
}

# Set the right-hand prompt
RPROMPT='$(git_prompt_string)'


## Colored man pages
export LESS_TERMCAP_mb=$'\E[01;32m'
export LESS_TERMCAP_md=$'\E[01;32m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;47;34m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;36m'
export LESS=-r

sorry, if some comments are in german. please ask, if you do not understand them.
you need the following packages installed, if you want to use it all:

  • fzf
  • mpv
  • zsh-autosuggestions
  • zsh-completions
  • zsh-history-substring-search
  • zsh-syntax-highlighting

i like especially the “play”, “fkill”, and “cd” function. the git information in directories with version control is really helpful, too. the best thing about fish is integrated as well: autosuggestions.

my .zshrc file is somewhat similar to chrysostomus’. we have worked together on it for a while and he maintains the manjaro-zsh-config package with it. but i did not need all the theming options and later started to add more functions and my own stuff.

if someone wants to start with zsh, i do not recommend to take my setup, but rather take the parts you like and start to build your own custom setup.

6 Likes

I picked up zsh from the old manjaro awesome respin. Once I got used to it, bash just didn’t cut it anymore. Later on I tried fish, which had some pretty nifty features, but also such alien syntax that it made scripting quite a chore. I managed to merge most of the things I liked in fish to my zsh configuration. Later still I found out about the wider scripting possibilities zsh offers over bash, though I rarely use them.

Manjaro-zsh-config is my configuration, with some parts stripped down so that it would be useful for more people. I started writing it when we had a conversation on whether or not manjaro should move to using zsh instead of bash by default (which I think we should do btw, in spirit of user friendliness).

Here are some highlights:

  1. pacman completion in the top terminals
  2. colored man pages and syntax highlighting in nano
  3. Syntax highlighting everywhere
  4. history substring search in middle left terminal. Also indicators for the exit code of previous command
  5. path and git prompt in bottom left corner
4 Likes

can you tell me more about fkill? it seems like an interesting addition

i copied it from here:

there are many more great examples using fzf to do stuff. choose whatever you like and modify them to your need.

1 Like

That’s my zsh with powerlevel9k theme:


I don’t have Manjaro icon so it’s Arch.

3 Likes

i use powerlevel9k and byobu for terminal tiling

4 Likes

@blaksuan19 how do you get the penguin?

os_icon option just put it on any side of the prompt

1 Like

Thanks.

I love this thread, here is my zsh. Pretty much default “darkblood” theme with modified colors to fit my WM theme.

Term_1

4 Likes

That. Is. Nice.

Like. Really. Nice!

1 Like

Yep, opened this to share the work like the conky thread :wink:

6 Likes

this looks cool and useful!
how did you achieve this?

i did a quick scan of manjaro-zsh-config but could not find anything related to “highlight” or “nano”, which could explain these improvements.

Oops, that’s actually done in nanorc. See bspwm edition dotfiles for details:

2 Likes

for nano syntax highlighting just install the package “nano-syntax-highlighting-git”

This isn’t necessary. Basic syntax highlighting is build in. But you need to enable it as @Chrysostomus already wrote.

am not sure about that but installing the package enables it

the package is basically a beefier version of a standard nanorc, that’s why it enables the highlighting

Forum kindly sponsored by