Last active
May 7, 2026 18:55
-
-
Save 8thgencore/acc94821638eb4a292ea56d7bd43f4c3 to your computer and use it in GitHub Desktop.
My linux setup script
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
| # >>> reference: https://carlosneto.dev/blog/2024/2024-02-08-starship-zsh/ | |
| # list files with details | |
| alias ll="ls -larht" | |
| # show confirm prompt | |
| alias rm="rm -i" | |
| # show all history lines | |
| alias history="history 1" | |
| # alias for scripts | |
| alias bat="batcat" | |
| alias fd="fdfind" | |
| # set the locale of the shell | |
| export LANG="en_US.UTF-8" | |
| # define VSCode as the default text editor | |
| export EDITOR="code -w" | |
| # include user-specific binaries and scripts | |
| export PATH="$HOME/.local/bin:$PATH" | |
| # add Go binaries to the PATH | |
| export PATH="$PATH:$HOME/go/bin" | |
| export PATH="$PATH:/usr/local/go/bin" | |
| # system wide cli | |
| export PATH="$PATH:/usr/local/bin" | |
| # python cli | |
| export PATH="$PATH:$HOME/.venv/bin" | |
| # colorize "kubectl diff" command outputs | |
| export KUBECTL_EXTERNAL_DIFF="colordiff -N -u" | |
| # specify characters considered as word boundaries for command line navigation | |
| export WORDCHARS="" | |
| # set the location and filename of the history file | |
| export HISTFILE="$HOME/.zsh_history" | |
| # set the maximum number of lines to be saved in the history file | |
| export HISTSIZE="100000" | |
| export SAVEHIST="$HISTSIZE" | |
| # fzf parameters used in all widgets - configure layout and wrapped the preview results (useful in large command rendering) | |
| export FZF_DEFAULT_OPTS="--height 100% --layout reverse --preview-window=wrap" | |
| # CTRL + R: put the selected history command in the preview window - "{}" will be replaced by item selected in fzf execution runtime | |
| export FZF_CTRL_R_OPTS="--preview 'echo {}'" | |
| # CTRL + T: set "fd-find" as search engine instead of "find" and exclude .git for the results | |
| export FZF_CTRL_T_COMMAND="fd --exclude .git --ignore-file $HOME/.my-custom-zsh/.fd-fzf-ignore" | |
| # CTRL + T: put the file content if item select is a file, or put tree command output if item selected is directory | |
| export FZF_CTRL_T_OPTS="--preview '[ -d {} ] && tree -C {} || bat --color=always --style=numbers {}'" | |
| # disable CTRL + S and CTRL + Q | |
| stty -ixon | |
| # enable comments "#" expressions in the prompt shell | |
| setopt INTERACTIVE_COMMENTS | |
| # append new history entries to the history file | |
| setopt APPEND_HISTORY | |
| # save each command to the history file as soon as it is executed | |
| setopt INC_APPEND_HISTORY | |
| # ignore recording duplicate consecutive commands in the history | |
| setopt HIST_IGNORE_DUPS | |
| # ignore commands that start with a space in the history | |
| setopt HIST_IGNORE_SPACE | |
| # >>> bindkey tip: to discovery the code of your keys, execute "$ cat -v" and press the key, the code will be printed in your shell. | |
| # use the ZLE (zsh line editor) in emacs mode. Useful to move the cursor in large commands | |
| bindkey -e | |
| # navigate words using Ctrl + arrow keys | |
| # >>> CRTL + right arrow | CRTL + left arrow | |
| bindkey "^[[1;5C" forward-word | |
| bindkey "^[[1;5D" backward-word | |
| # macosx override | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| # >>> OPT + right arrow | OPT + left arrow | |
| bindkey "^[^[[C" forward-word | |
| bindkey "^[^[[D" backward-word | |
| fi | |
| # jump to the start and end of the command line | |
| # >>> CTRL + A | CTRL + E | |
| bindkey "^A" beginning-of-line | |
| bindkey "^E" end-of-line | |
| # >>> Home | End | |
| bindkey "^[[H" beginning-of-line | |
| bindkey "^[[F" end-of-line | |
| # navigate menu for command output | |
| zstyle ':completion:*:*:*:*:*' menu select | |
| bindkey '^[[Z' reverse-menu-complete | |
| # delete characters using the "delete" key | |
| bindkey "^[[3~" delete-char | |
| # fzf alias: CTRL + SPACE (gadget parameters configured in the FZF_CTRL_T_COMMAND environment variable) | |
| bindkey "^@" fzf-file-widget | |
| # >>> load ZSH plugin | |
| # load zsh-autosuggestions | |
| source "$HOME/.my-custom-zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" | |
| # load zsh-syntax-highlighting | |
| source "$HOME/.my-custom-zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" | |
| # load fzf keybindings and completions | |
| eval "$(fzf --zsh)" | |
| # keep prefix history search after plugin keybindings are loaded | |
| autoload -Uz up-line-or-beginning-search down-line-or-beginning-search | |
| zle -N up-line-or-beginning-search | |
| zle -N down-line-or-beginning-search | |
| bindkey "^[[A" up-line-or-beginning-search | |
| bindkey "^[[B" down-line-or-beginning-search | |
| bindkey "^[OA" up-line-or-beginning-search | |
| bindkey "^[OB" down-line-or-beginning-search | |
| # start Starship prompt | |
| eval "$(starship init 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
| #!/usr/bin/env bash | |
| set -e | |
| # -------------------------------------------- | |
| # Fancy output | |
| # -------------------------------------------- | |
| RED=$(tput setaf 1) | |
| GREEN=$(tput setaf 2) | |
| YELLOW=$(tput setaf 3) | |
| RESET=$(tput sgr0) | |
| info() { echo "${YELLOW}[INFO]${RESET} $*"; } | |
| success() { echo "${GREEN}[OK]${RESET} $*"; } | |
| error() { echo "${RED}[ERR]${RESET} $*" >&2; } | |
| # -------------------------------------------- | |
| # Update system | |
| # -------------------------------------------- | |
| info "Updating system packages..." | |
| sudo apt-get update -qq | |
| sudo apt-get upgrade -y -qq | |
| sudo apt-get install -y -qq wget curl git build-essential ca-certificates | |
| # -------------------------------------------- | |
| # Install Zsh if not installed | |
| # -------------------------------------------- | |
| if ! command -v zsh >/dev/null 2>&1; then | |
| info "Installing Zsh..." | |
| sudo apt-get update -qq | |
| sudo apt-get install -y -qq zsh | |
| else | |
| success "Zsh already installed: $(zsh --version)" | |
| fi | |
| # -------------------------------------------- | |
| # Install Oh My Zsh if not installed | |
| # -------------------------------------------- | |
| if [ ! -d "$HOME/.oh-my-zsh" ]; then | |
| info "Installing Oh My Zsh..." | |
| RUNZSH=no CHSH=no sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| success "Oh My Zsh installed." | |
| else | |
| success "Oh My Zsh already installed." | |
| fi | |
| # -------------------------------------------- | |
| # Install Zsh plugins into $HOME/.my-custom-zsh | |
| # -------------------------------------------- | |
| CUSTOM_ZSH_DIR="$HOME/.my-custom-zsh" | |
| mkdir -p "$CUSTOM_ZSH_DIR" | |
| declare -A PLUGINS=( | |
| ["zsh-autosuggestions"]="https://github.com/zsh-users/zsh-autosuggestions.git" | |
| ["zsh-syntax-highlighting"]="https://github.com/zsh-users/zsh-syntax-highlighting.git" | |
| ["zsh-completions"]="https://github.com/zsh-users/zsh-completions.git" | |
| ["zsh-history-substring-search"]="https://github.com/zsh-users/zsh-history-substring-search.git" | |
| ) | |
| for name in "${!PLUGINS[@]}"; do | |
| dir="$CUSTOM_ZSH_DIR/$name" | |
| if [ ! -d "$dir" ]; then | |
| info "Installing Zsh plugin: $name" | |
| git clone --depth=1 "${PLUGINS[$name]}" "$dir" >/dev/null 2>&1 | |
| success "$name installed." | |
| else | |
| success "$name already installed." | |
| fi | |
| done | |
| # -------------------------------------------- | |
| # Install CLI tools (check and install if missing) | |
| # -------------------------------------------- | |
| TOOLS=(git curl bat zsh starship btop fd-find fzf gdu lazydocker lazygit byobu) | |
| info "Checking CLI tools..." | |
| for tool in "${TOOLS[@]}"; do | |
| if ! command -v "$tool" >/dev/null 2>&1; then | |
| info "Installing $tool..." | |
| case "$tool" in | |
| bat) | |
| sudo apt-get install -y bat | |
| echo 'alias bat="batcat"' >> ~/.zshrc | |
| ;; | |
| fd-find) | |
| sudo apt-get install -y fd-find | |
| echo 'alias fd="fdfind"' >> ~/.zshrc | |
| ;; | |
| lazydocker) | |
| curl -s https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash | |
| ;; | |
| lazygit) | |
| LAZYGIT_VER=$(curl -s https://api.github.com/repos/jesseduffield/lazygit/releases/latest | grep tag_name | cut -d '"' -f 4) | |
| curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/download/${LAZYGIT_VER}/lazygit_${LAZYGIT_VER#v}_Linux_x86_64.tar.gz" | |
| sudo tar xf lazygit.tar.gz -C /usr/local/bin lazygit && rm lazygit.tar.gz | |
| ;; | |
| *) | |
| sudo apt-get install -y "$tool" | |
| ;; | |
| esac | |
| else | |
| success "$tool already installed." | |
| fi | |
| done | |
| # -------------------------------------------- | |
| # Install Go (latest) | |
| # -------------------------------------------- | |
| if ! command -v go >/dev/null 2>&1; then | |
| info "Installing the latest version of Go..." | |
| LATEST_GO=$(wget -qO- https://golang.org/dl/ | grep -oP 'go\K[0-9]+\.[0-9]+\.[0-9]+(?=\.linux-amd64\.tar\.gz)' | head -n1) | |
| wget -q https://dl.google.com/go/go${LATEST_GO}.linux-amd64.tar.gz | |
| sudo rm -rf /usr/local/go | |
| sudo tar -C /usr/local -xzf go${LATEST_GO}.linux-amd64.tar.gz | |
| rm -f go${LATEST_GO}.linux-amd64.tar.gz | |
| echo 'export GOROOT=/usr/local/go | |
| export GOPATH=$HOME/go | |
| export PATH=$GOPATH/bin:$GOROOT/bin:$PATH' >> ~/.profile | |
| source ~/.profile | |
| success "Go $(go version) installed." | |
| else | |
| success "Go already installed: $(go version)" | |
| fi | |
| # -------------------------------------------- | |
| # Install Docker | |
| # -------------------------------------------- | |
| if ! command -v docker >/dev/null 2>&1; then | |
| info "Installing Docker..." | |
| curl -fsSL https://get.docker.com -o get-docker.sh | |
| sudo sh get-docker.sh | |
| sudo usermod -aG docker "$(whoami)" | |
| rm -f get-docker.sh | |
| success "Docker installed." | |
| else | |
| success "Docker already installed: $(docker --version)" | |
| fi | |
| # -------------------------------------------- | |
| # Final steps | |
| # -------------------------------------------- | |
| chsh -s "$(command -v zsh)" | |
| success "Default shell set to Zsh." | |
| info "All done! Reboot your server to apply changes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment