Created
August 24, 2025 09:37
-
-
Save fox34/90e67597aa349a8df079da7ae9cdff7f to your computer and use it in GitHub Desktop.
Lightweight and simple zsh "framework" with autosuggestions and syntax highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # History | |
| HISTFILE="$HOME/.zsh_history" | |
| HISTSIZE=10000 | |
| SAVEHIST=10000 | |
| setopt extended_history # record timestamp of command in HISTFILE | |
| setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE | |
| setopt hist_ignore_dups # ignore duplicated commands history list | |
| setopt hist_ignore_all_dups # only show last variant of duplicates | |
| setopt hist_verify # show command with history expansion to user before running it | |
| setopt share_history # share command history data between shells (read/write instead of append) | |
| # Key bindings | |
| # https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/key-bindings.zsh | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets | |
| # Make sure that the terminal is in application mode when zle is active, since | |
| # only then values from $terminfo are valid | |
| if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then | |
| function zle-line-init() { | |
| echoti smkx | |
| } | |
| function zle-line-finish() { | |
| echoti rmkx | |
| } | |
| zle -N zle-line-init | |
| zle -N zle-line-finish | |
| fi | |
| # Use emacs key bindings | |
| bindkey -e | |
| # [PageUp] - Up a line of history | |
| if [[ -n "${terminfo[kpp]}" ]]; then | |
| bindkey -M emacs "${terminfo[kpp]}" up-line-or-history | |
| bindkey -M viins "${terminfo[kpp]}" up-line-or-history | |
| bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history | |
| fi | |
| # [PageDown] - Down a line of history | |
| if [[ -n "${terminfo[knp]}" ]]; then | |
| bindkey -M emacs "${terminfo[knp]}" down-line-or-history | |
| bindkey -M viins "${terminfo[knp]}" down-line-or-history | |
| bindkey -M vicmd "${terminfo[knp]}" down-line-or-history | |
| fi | |
| # Start typing + [Up-Arrow] - fuzzy find history forward | |
| autoload -U up-line-or-beginning-search | |
| zle -N up-line-or-beginning-search | |
| bindkey -M emacs "^[[A" up-line-or-beginning-search | |
| bindkey -M viins "^[[A" up-line-or-beginning-search | |
| bindkey -M vicmd "^[[A" up-line-or-beginning-search | |
| if [[ -n "${terminfo[kcuu1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| fi | |
| # Start typing + [Down-Arrow] - fuzzy find history backward | |
| autoload -U down-line-or-beginning-search | |
| zle -N down-line-or-beginning-search | |
| bindkey -M emacs "^[[B" down-line-or-beginning-search | |
| bindkey -M viins "^[[B" down-line-or-beginning-search | |
| bindkey -M vicmd "^[[B" down-line-or-beginning-search | |
| if [[ -n "${terminfo[kcud1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search | |
| bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search | |
| bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search | |
| fi | |
| # [Home] - Go to beginning of line | |
| if [[ -n "${terminfo[khome]}" ]]; then | |
| bindkey -M emacs "${terminfo[khome]}" beginning-of-line | |
| bindkey -M viins "${terminfo[khome]}" beginning-of-line | |
| bindkey -M vicmd "${terminfo[khome]}" beginning-of-line | |
| fi | |
| # [End] - Go to end of line | |
| if [[ -n "${terminfo[kend]}" ]]; then | |
| bindkey -M emacs "${terminfo[kend]}" end-of-line | |
| bindkey -M viins "${terminfo[kend]}" end-of-line | |
| bindkey -M vicmd "${terminfo[kend]}" end-of-line | |
| fi | |
| # [Shift-Tab] - move through the completion menu backwards | |
| if [[ -n "${terminfo[kcbt]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete | |
| bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete | |
| bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete | |
| fi | |
| # [Backspace] - delete backward | |
| bindkey -M emacs '^?' backward-delete-char | |
| bindkey -M viins '^?' backward-delete-char | |
| bindkey -M vicmd '^?' backward-delete-char | |
| # [Delete] - delete forward | |
| if [[ -n "${terminfo[kdch1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kdch1]}" delete-char | |
| bindkey -M viins "${terminfo[kdch1]}" delete-char | |
| bindkey -M vicmd "${terminfo[kdch1]}" delete-char | |
| else | |
| bindkey -M emacs "^[[3~" delete-char | |
| bindkey -M viins "^[[3~" delete-char | |
| bindkey -M vicmd "^[[3~" delete-char | |
| bindkey -M emacs "^[3;5~" delete-char | |
| bindkey -M viins "^[3;5~" delete-char | |
| bindkey -M vicmd "^[3;5~" delete-char | |
| fi | |
| # [Ctrl-Delete] - delete whole forward-word | |
| bindkey -M emacs '^[[3;5~' kill-word | |
| bindkey -M viins '^[[3;5~' kill-word | |
| bindkey -M vicmd '^[[3;5~' kill-word | |
| # [Ctrl-RightArrow] - move forward one word | |
| bindkey -M emacs '^[[1;5C' forward-word | |
| bindkey -M viins '^[[1;5C' forward-word | |
| bindkey -M vicmd '^[[1;5C' forward-word | |
| # [Ctrl-LeftArrow] - move backward one word | |
| bindkey -M emacs '^[[1;5D' backward-word | |
| bindkey -M viins '^[[1;5D' backward-word | |
| bindkey -M vicmd '^[[1;5D' backward-word | |
| bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark | |
| bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls | |
| bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. | |
| bindkey ' ' magic-space # [Space] - don't do history expansion | |
| # Edit the current command line in $VISUAL (or $EDITOR / `vi` if not set) | |
| autoload -U edit-command-line | |
| zle -N edit-command-line | |
| bindkey '\C-x\C-e' edit-command-line | |
| # file rename magick | |
| bindkey "^[m" copy-prev-shell-word | |
| # Autocomplete | |
| autoload -Uz compinit | |
| ZSH_COMPDUMP="${HOME}/.zcompdump" | |
| # Don't complete uninteresting users | |
| zstyle ':completion:*:*:*:users' ignored-patterns \ | |
| adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \ | |
| clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \ | |
| gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \ | |
| ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ | |
| named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \ | |
| operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \ | |
| rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \ | |
| usbmux uucp vcsa wwwrun xfs '_*' | |
| # ... unless we really want to. | |
| zstyle '*' single-ignored show | |
| compinit -d "${ZSH_COMPDUMP}" | |
| # On error messages: | |
| # compaudit # -> Check output | |
| # compaudit | xargs chmod g-w # Try to fix permissions | |
| # git | |
| autoload -Uz vcs_info | |
| # execute for each prompt | |
| precmd_vcs_info() { vcs_info } | |
| precmd_functions+=( precmd_vcs_info ) | |
| zstyle ':vcs_info:*' enable git | |
| zstyle ':vcs_info:git:*' check-for-changes true | |
| zstyle ':vcs_info:git:*' unstagedstr '*' | |
| zstyle ':vcs_info:git:*' stagedstr '+' | |
| zstyle ':vcs_info:git:*' formats ' (%b%u%c)' # (%s)-[%b]%u%c- | |
| zstyle ':vcs_info:git:*' actionformats ' (%b|%a%u%c)' # (%s)-[%b|%a]%u%c- | |
| # Theme | |
| autoload -U colors && colors | |
| # Expand variables and commands in PROMPT variables | |
| setopt prompt_subst | |
| PROMPT="%(?:%{$fg_bold[green]%}%1{➜%} :%{$fg_bold[red]%}%1{➜%} ) %{$fg[cyan]%}%c%{$reset_color%}" | |
| PROMPT+='%{$fg[yellow]%}${vcs_info_msg_0_}%{$reset_color%} ' | |
| # Command aliases | |
| alias ls="ls --color=tty" | |
| alias lsa='ls -lah' | |
| alias l='ls -lah' | |
| alias ll='ls -lh' | |
| alias la='ls -lAh' | |
| alias apt-get="sudo apt-get" | |
| alias apt="sudo apt" | |
| alias systemctl="sudo systemctl" | |
| alias journalctl="sudo journalctl" | |
| alias chown="sudo chown" | |
| alias chmod="sudo chmod" | |
| alias iftop="sudo iftop -B" | |
| alias htop="sudo htop" | |
| alias docker="sudo docker" | |
| alias docker-compose="sudo docker-compose" | |
| alias dc="sudo docker compose" | |
| # https://old.reddit.com/r/linuxadmin/comments/13fjqg2/psa_stop_using_mount_to_list_mounts/jjyi1mh/ | |
| alias lsblk="lsblk -fe 1,7" | |
| alias ffprobe="ffprobe -hide_banner" | |
| alias ffmpeg="ffmpeg -hide_banner -loglevel warning" | |
| # Plugins | |
| # sudo apt install zsh-syntax-highlighting zsh-autosuggestions | |
| source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
| source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # History | |
| HISTFILE="$HOME/.zsh_history" | |
| HISTSIZE=10000 | |
| SAVEHIST=10000 | |
| setopt extended_history # record timestamp of command in HISTFILE | |
| setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE | |
| setopt hist_ignore_dups # ignore duplicated commands history list | |
| setopt hist_ignore_all_dups # only show last variant of duplicates | |
| setopt hist_verify # show command with history expansion to user before running it | |
| setopt share_history # share command history data between shells (read/write instead of append) | |
| # Key bindings | |
| # https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/key-bindings.zsh | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins | |
| # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets | |
| # Make sure that the terminal is in application mode when zle is active, since | |
| # only then values from $terminfo are valid | |
| if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then | |
| function zle-line-init() { | |
| echoti smkx | |
| } | |
| function zle-line-finish() { | |
| echoti rmkx | |
| } | |
| zle -N zle-line-init | |
| zle -N zle-line-finish | |
| fi | |
| # Use emacs key bindings | |
| bindkey -e | |
| # [PageUp] - Up a line of history | |
| if [[ -n "${terminfo[kpp]}" ]]; then | |
| bindkey -M emacs "${terminfo[kpp]}" up-line-or-history | |
| bindkey -M viins "${terminfo[kpp]}" up-line-or-history | |
| bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history | |
| fi | |
| # [PageDown] - Down a line of history | |
| if [[ -n "${terminfo[knp]}" ]]; then | |
| bindkey -M emacs "${terminfo[knp]}" down-line-or-history | |
| bindkey -M viins "${terminfo[knp]}" down-line-or-history | |
| bindkey -M vicmd "${terminfo[knp]}" down-line-or-history | |
| fi | |
| # Start typing + [Up-Arrow] - fuzzy find history forward | |
| autoload -U up-line-or-beginning-search | |
| zle -N up-line-or-beginning-search | |
| bindkey -M emacs "^[[A" up-line-or-beginning-search | |
| bindkey -M viins "^[[A" up-line-or-beginning-search | |
| bindkey -M vicmd "^[[A" up-line-or-beginning-search | |
| if [[ -n "${terminfo[kcuu1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search | |
| fi | |
| # Start typing + [Down-Arrow] - fuzzy find history backward | |
| autoload -U down-line-or-beginning-search | |
| zle -N down-line-or-beginning-search | |
| bindkey -M emacs "^[[B" down-line-or-beginning-search | |
| bindkey -M viins "^[[B" down-line-or-beginning-search | |
| bindkey -M vicmd "^[[B" down-line-or-beginning-search | |
| if [[ -n "${terminfo[kcud1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search | |
| bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search | |
| bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search | |
| fi | |
| # [Home] - Go to beginning of line | |
| if [[ -n "${terminfo[khome]}" ]]; then | |
| bindkey -M emacs "${terminfo[khome]}" beginning-of-line | |
| bindkey -M viins "${terminfo[khome]}" beginning-of-line | |
| bindkey -M vicmd "${terminfo[khome]}" beginning-of-line | |
| fi | |
| # [End] - Go to end of line | |
| if [[ -n "${terminfo[kend]}" ]]; then | |
| bindkey -M emacs "${terminfo[kend]}" end-of-line | |
| bindkey -M viins "${terminfo[kend]}" end-of-line | |
| bindkey -M vicmd "${terminfo[kend]}" end-of-line | |
| fi | |
| # [Shift-Tab] - move through the completion menu backwards | |
| if [[ -n "${terminfo[kcbt]}" ]]; then | |
| bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete | |
| bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete | |
| bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete | |
| fi | |
| # [Backspace] - delete backward | |
| bindkey -M emacs '^?' backward-delete-char | |
| bindkey -M viins '^?' backward-delete-char | |
| bindkey -M vicmd '^?' backward-delete-char | |
| # [Delete] - delete forward | |
| if [[ -n "${terminfo[kdch1]}" ]]; then | |
| bindkey -M emacs "${terminfo[kdch1]}" delete-char | |
| bindkey -M viins "${terminfo[kdch1]}" delete-char | |
| bindkey -M vicmd "${terminfo[kdch1]}" delete-char | |
| else | |
| bindkey -M emacs "^[[3~" delete-char | |
| bindkey -M viins "^[[3~" delete-char | |
| bindkey -M vicmd "^[[3~" delete-char | |
| bindkey -M emacs "^[3;5~" delete-char | |
| bindkey -M viins "^[3;5~" delete-char | |
| bindkey -M vicmd "^[3;5~" delete-char | |
| fi | |
| # [Ctrl-Delete] - delete whole forward-word | |
| bindkey -M emacs '^[[3;5~' kill-word | |
| bindkey -M viins '^[[3;5~' kill-word | |
| bindkey -M vicmd '^[[3;5~' kill-word | |
| # [Ctrl-RightArrow] - move forward one word | |
| bindkey -M emacs '^[[1;5C' forward-word | |
| bindkey -M viins '^[[1;5C' forward-word | |
| bindkey -M vicmd '^[[1;5C' forward-word | |
| # [Ctrl-LeftArrow] - move backward one word | |
| bindkey -M emacs '^[[1;5D' backward-word | |
| bindkey -M viins '^[[1;5D' backward-word | |
| bindkey -M vicmd '^[[1;5D' backward-word | |
| bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark | |
| bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls | |
| bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. | |
| bindkey ' ' magic-space # [Space] - don't do history expansion | |
| # Edit the current command line in $VISUAL (or $EDITOR / `vi` if not set) | |
| autoload -U edit-command-line | |
| zle -N edit-command-line | |
| bindkey '\C-x\C-e' edit-command-line | |
| # file rename magick | |
| bindkey "^[m" copy-prev-shell-word | |
| # Autocomplete | |
| autoload -Uz compinit | |
| ZSH_COMPDUMP="${HOME}/.zcompdump" | |
| # Don't complete uninteresting users | |
| zstyle ':completion:*:*:*:users' ignored-patterns \ | |
| adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \ | |
| clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \ | |
| gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \ | |
| ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ | |
| named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \ | |
| operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \ | |
| rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \ | |
| usbmux uucp vcsa wwwrun xfs '_*' | |
| # ... unless we really want to. | |
| zstyle '*' single-ignored show | |
| compinit -d "${ZSH_COMPDUMP}" | |
| # On error messages: | |
| # compaudit # -> Check output | |
| # compaudit | xargs chmod g-w # Try to fix permissions | |
| # git | |
| autoload -Uz vcs_info | |
| # execute for each prompt | |
| precmd_vcs_info() { vcs_info } | |
| precmd_functions+=( precmd_vcs_info ) | |
| zstyle ':vcs_info:*' enable git | |
| zstyle ':vcs_info:git:*' check-for-changes true | |
| zstyle ':vcs_info:git:*' unstagedstr '*' | |
| zstyle ':vcs_info:git:*' stagedstr '+' | |
| zstyle ':vcs_info:git:*' formats ' (%b%u%c)' # (%s)-[%b]%u%c- | |
| zstyle ':vcs_info:git:*' actionformats ' (%b|%a%u%c)' # (%s)-[%b|%a]%u%c- | |
| # Theme | |
| autoload -U colors && colors | |
| # Expand variables and commands in PROMPT variables | |
| setopt prompt_subst | |
| PROMPT="%(?:%{$fg_bold[green]%}%1{➜%} :%{$fg_bold[red]%}%1{➜%} ) %{$fg[cyan]%}%c%{$reset_color%}" | |
| PROMPT+='%{$fg[yellow]%}${vcs_info_msg_0_}%{$reset_color%} ' | |
| # Apple quirks | |
| # https://apple.stackexchange.com/a/458705 + https://superuser.com/a/1303096 | |
| SHELL_SESSIONS_DISABLE=1 | |
| export PATH="/usr/local/sbin:/usr/local/bin:$PATH" | |
| # https://stackoverflow.com/a/41054093 | |
| export GPG_TTY=$(tty) | |
| # Homebrew configuration | |
| export HOMEBREW_NO_ENV_HINTS=1 | |
| export HOMEBREW_NO_ANALYTICS=1 | |
| # Command aliases | |
| alias ls="ls --color=tty" | |
| alias lsa='ls -lah' | |
| alias l='ls -lah' | |
| alias ll='ls -lh' | |
| alias la='ls -lAh' | |
| alias dig="dig +noall +answer +multiline" | |
| alias ffprobe="ffprobe -hide_banner" | |
| alias ffmpeg="ffmpeg -hide_banner -loglevel warning" | |
| # Plugins | |
| # brew install zsh-syntax-highlighting zsh-autosuggestions | |
| source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
| source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment