Skip to content

Instantly share code, notes, and snippets.

@bgeneto
Last active September 5, 2023 13:58
Show Gist options
  • Save bgeneto/7b8a806b930350ff6a3ebd952f569415 to your computer and use it in GitHub Desktop.
Save bgeneto/7b8a806b930350ff6a3ebd952f569415 to your computer and use it in GitHub Desktop.
zsh install and config

Install sofware dependencies

#export pkgmngt=dnf
export pkgmngt=apt
sudo $pkgmngt update && sudo $pkgmngt install tree exa zsh wget curl unzip fontconfig -y

Font Install

Install any Nerd font of your choice in order to support icons, symbols...

curl -k https://cloud.bgeneto.com.br:4433/s/iTtB3KNaGnRqEYs/download/Hack%20Mono.zip --output ./Hack.zip && mkdir -p ~/.fonts && unzip -d ~/.fonts ./Hack.zip
curl -k https://cloud.bgeneto.com.br:4433/s/ZMKi7ZLBX6mQ76Y/download/MesloLGS%20NF.zip --output ./Meslo.zip && mkdir -p ~/.fonts && unzip -d ~/.fonts ./Meslo.zip
# update font cache
fc-cache -f

Install zsh4humans

zsh4humans is a turnkey configuration for zsh that works really well out of the box.

if command -v curl >/dev/null 2>&1; then
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/romkatv/zsh4humans/v5/install)"
else
  sh -c "$(wget -O- https://raw.githubusercontent.com/romkatv/zsh4humans/v5/install)"
fi

Customize you zsh shell

This command adds lines below to your ~/.zshrc file in order to install usefull plugins, alias, functions...

cat << 'EOF' >> $HOME/.zshrc

# -------------------------
#  custom sytle & plugins
# -------------------------

zstyle ':z4h:fzf-complete' recurse-dirs 'yes'
z4h load ohmyzsh/ohmyzsh/plugins/docker
z4h load ohmyzsh/ohmyzsh/plugins/docker-compose
z4h load ohmyzsh/ohmyzsh/plugins/history
z4h load ohmyzsh/ohmyzsh/plugins/extract

# -------------------------
#  custom export vars
# -------------------------

export VISUAL="vim"
export EDITOR="vim"

# -------------------------
#  shell optimizations
# -------------------------

# increase memory stack size
ulimit -s unlimited
ulimit -n 65536

# -------------------------
#  custom aliases
# -------------------------
alias history='history 1'
alias ll='exa -lbF'
alias la='exa -lbhHigmuSa --time-style=long-iso --color-scale'
#alias ll='exa -lbF --git'
#alias la='exa -lbhHigmuSa --time-style=long-iso --color-scale --git'
#alias ll='ls -hall --color=always'
#alias la='ls -hall --color=always'
alias free='free -h'
alias suvi='sudo vim'
alias suvim='sudo vim'
alias update="sudo $pkgmngt update"
alias upgrade='sudo $pkgmngt update && sleep 3 && sudo $pkgmngt upgrade'
alias inst='sudo $pkgmngt install'
alias chme='sudo chown -R bgeneto:bgeneto'
alias sll='sudo ls -hall --color=always'
alias sla='sudo ls -hall --color=always'
alias sls='sudo ls -hall --color=always'
alias listen='sudo lsof -i -P -n | grep LISTEN'
alias compress='tar --use-compress-program="pigz -k -5" -cf '
alias dsp='docker system prune'
alias ipt='iptables -nL --line-numbers'
alias scp='noglob scp'
alias df='df -hT'

# -------------------------
#  custom functions
# -------------------------

ssh-agent-start(){
  if [ -z "$SSH_AUTH_SOCK" ] ; then
    eval `ssh-agent -s`
    ssh-add ~/.ssh/id_rsa
  fi
}

fail2ban-status(){
  JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
  for JAIL in $JAILS
    do
      fail2ban-client status $JAIL
    done
}

mkdcd(){
  mkdir -p -- "$1" && cd -P -- "$1"
}

now(){
    export now=$(date +"%Y-%m-%dT%H%M%S")
}

# list systemd aliases and functions
listd(){
  echo -e "${BLD}${RED} --> SYSTEM LEVEL <--${NRM}"
  tree /etc/systemd/system
  [[ -d "$HOME"/.config/systemd/user/default.target.wants ]] &&
    (echo -e "${BLD}${RED} --> USER LEVEL <--${NRM}" ; \
    tree "$HOME"/.config/systemd/user)
  }

# systemlevel
start() { sudo systemctl start "$1"; }
stop() { sudo systemctl stop "$1"; }
restart() { sudo systemctl restart "$1"; }
status() { sudo systemctl status "$1"; }
enabled() { sudo systemctl enable "$1"; listd; }
disabled() { sudo systemctl disable "$1"; listd; }

# userlevel
ustart() { systemctl --user start "$1"; }
ustop() { systemctl --user stop "$1"; }
ustatus() { systemctl --user status "$1"; }
uenabled() { systemctl --user enable "$1"; }
udisabled() { systemctl --user disable "$1"; }

runtime() {
  # how long has a process been running
  [[ -n "$1" ]] || return 1
  if pidof -q -x "$1"; then
    ps --no-headers -o %t $(pidof -x "$1" | awk '{ print $(NF) }')
  else
    return 1
  fi
}

ff() {
  [[ -n "$1" ]] || return 1
  find . -type f -name "$1"
}

fd() {
  [[ -n "$1" ]] || return 1
  find . -type d -name "$1"
}

# -------------------------
#  intel mkl and compilers
# -------------------------

setvars_sh=/opt/intel/oneapi/setvars.sh
setvars_cfg=$HOME/setvars.cfg
if [[ -f "$setvars_sh" ]]; then
    if [[ -f "$setvars_cfg" ]]; then
        source $setvars_sh --config="$setvars_cfg" > /dev/null 2>&1
    else
        source $setvars_sh > /dev/null 2>&1
    fi
fi

# -------------------------
#  openblas library
# -------------------------

openblas_dir=/opt/OpenBLAS
if [[ -d "$openblas_dir" ]]; then
    export C_INCLUDE_PATH=$C_INCLUDE_PATH:$openblas_dir/include
    export CPATH=$CPATH:$openblas_dir/include
    export LIBRARY_PATH=$LIBRARY_PATH:$openblas_dir/lib
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$openblas_dir/lib
fi

# pyenv path
export PYENV_ROOT="$HOME/.pyenv"
if [[ -d "$PYENV_ROOT" ]]; then
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
else
    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
fi
EOF

Refresh your shell

Check if everything went fine by refreshing/changing your shell:

exec zsh

Change your default shell

Finally use the chsh command to change your default shell permanently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment