Skip to content

Instantly share code, notes, and snippets.

@richardnfag
Created April 23, 2021 02:09
Show Gist options
  • Save richardnfag/2ed0621dcccf96299758af97aa5cddee to your computer and use it in GitHub Desktop.
Save richardnfag/2ed0621dcccf96299758af97aa5cddee to your computer and use it in GitHub Desktop.
ZSH customization script
#!/bin/sh
user_setup(){
sed -e '/PROMPT/ s/^#*/#/' -i $1 2> /dev/null
cat >> $1 <<EOF
# Find and set branch name var if in git repository.
function git_branch_name()
{
echo $(git branch 2>/dev/null | grep '^*' | colrm 1 2)
}
# Enable substitution in the prompt.
setopt prompt_subst
# Config for prompt. PS1 synonym.
RPROMPT='~ %F{49}$(git_branch_name)%f'
PATH="$HOME/.local/bin:$PATH"
EOF
}
system_setup(){
sudo sed -e '/PROMPT/ s/^#*/#/' -i $1 2> /dev/null
sudo cat >> $1 <<EOF
PROMPT='%F{49}('$(whoami)') λ%f %2/ '
alias ls='ls --color=auto'
alias grep='grep --color=auto'
bindkey "^[[3~" delete-char
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^H" backward-kill-word
bindkey "^[[3;5~" kill-word
setopt histignorealldups sharehistory
# Keep 10000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
# Use modern completion system
autoload -Uz compinit
compinit
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
EOF
}
root_setup(){
sudo sed -e '/PROMPT/ s/^#*/#/' -i $1 2> /dev/null
sudo cat >> /root/.zshrc <<EOF
PROMPT='%F{196}(root) λ%f %2/ '
EOF
}
fedora(){
sudo dnf install -y zsh
echo 'Installing zsh in fedora'
user_setup /home/$(whoami)/.zshrc
user_setup /etc/skel/.zshrc
system_setup /etc/zshrc
}
ubuntu(){
sudo apt install -y zsh
echo 'Installing zsh in ubuntu'
user_setup /home/$(whoami)/.zshrc
user_setup /etc/skel/.zshrc
system_setup /etc/zsh/zshrc
}
case $1 in
fedora)
fedora
;;
ubuntu)
ubuntu
;;
*)
echo 'Usage: ' $0 ' [ ubuntu | fedora ]'
echo 'Example: ' $0 ' ubuntu'
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment