Skip to content

Instantly share code, notes, and snippets.

@dshafik
Last active August 20, 2024 15:30
Show Gist options
  • Save dshafik/67fe3e0ba5096a00c91cccb0792a884b to your computer and use it in GitHub Desktop.
Save dshafik/67fe3e0ba5096a00c91cccb0792a884b to your computer and use it in GitHub Desktop.
Terminal Nirvana
# Setup ENV
FZF_TAB_PLUGIN=$HOME/src/fzf-tab/fzf-tab.plugin.zsh
BREW_PREFIX="$(brew --prefix)"
# Enable brew zsh-completions
if type brew &>/dev/null; then
FPATH=${BREW_PREFIX}/share/zsh-completions:$FPATH
autoload -U compinit
compinit
fi
# Enable iTerm2 Shell Integration
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# Setup the Brew shell env
eval "$(${BREW_PREFIX}/bin/brew shellenv)"
# Init Starship
eval "$(starship init zsh)"
# Enable zoxide, override `cd`
eval "$(zoxide init zsh --cmd cd)"
# Enable fzf
eval "$(fzf --zsh)"
# Enable fzf when using tab completion
if test -f "$FZF_TAB_PLUGIN"; then
source $FZF_TAB_PLUGIN
else
echo "fzf-tab is not installed, install it from https://github.com/Aloxaf/fzf-tab and set FZF_TAB_PLUGIN"
fi
# Enable command syntax highlighting
source ${BREW_PREFIX}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Enable zsh auto-suggestions
source ${BREW_PREFIX}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# Enable zsh history substring search
source ${BREW_PREFIX}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
# Customize fzf
_fzf_compgen_path() {
fd --hidden --exclude .git . "$1"
}
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}
_fzf_comprun() {
local command=$1
shift
case "$command" in
cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
cat|bat) fzf --preview 'bat -n --color=always {}' "$@" ;;
*) fzf --preview '$HOME/bin/fzf-preview.sh {}' "$@" ;;
esac
}
# Aliases
alias cat=bat
alias ls="eza --icons=always --color=always --git"
alias stree='/Applications/SourceTree.app/Contents/Resources/stree'
# Enable history navigation using the up and down keys
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# Enable using fzf preview with eza when using tab completion with `cd`
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:*' fzf-preview '$HOME/bin/fzf-preview.sh $realpath'
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza --tree --color=always --icons=always --git $realpath | head -200'
zstyle ':fzf-tab:*' switch-group '<' '>'
# Configure zsh history
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=2000
export SAVEHIST=$HISTSIZE
setopt share_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_verify
setopt hist_ignore_space
# Enable auto-complete of aliases
setopt complete_aliases
# Enable comments
setopt interactive_comments
# Tool Exports
export BAT_THEME="Monokai Extended Bright"
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always {}'"
export FZF_ALT_C_COMMAND="fd --type=d --hiden --strip-cwd-prefix --exclude .git"
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"
# Env Exports
export PHP_IDE_CONFIG=serverName=localhost
# Path
export PATH=.:vendor/bin:$HOME/bin:$HOME/.composer/vendor/bin:$PATH
#!/bin/bash
if test -d "$@"; then
eza --tree --color=always --icons=always --git "$@" | head -200
else
bat -n --color=always "$@"
fi
export HISTFILE=$HOME/.zsh_history # Save the history in your home directory as .zsh_history
export HISTSIZE=2000 # Set the history size to 2000 commands
export SAVEHIST=$HISTSIZE # Store the same number to disk
setopt share_history # Share history between sessions
setopt hist_expire_dups_first # Remove duplicates first when HISTSIZE is met
setopt hist_ignore_dups # If the same command is issued multiple times in a row, ignore the dupes
setopt hist_verify # Allow editing the command before executing upon retrieval from thie history
setopt hist_ignore_space # Do not add commands prefixed with a space to the history
format = """
$username\
$hostname\
$localip\
$shlvl\
$singularity\
$directory\
$vcsh\
$fossil_branch\
$git_branch\
$git_commit\
$git_state\
$git_metrics\
$git_status\
$hg_branch\
$pijul_channel\
$package\
$c\
$cmake\
$cobol\
$daml\
$dart\
$deno\
$dotnet\
$elixir\
$elm\
$erlang\
$fennel\
$golang\
$guix_shell\
$haskell\
$haxe\
$helm\
$java\
$julia\
$kotlin\
$gradle\
$lua\
$nim\
$nodejs\
$ocaml\
$opa\
$perl\
$php\
$pulumi\
$purescript\
$python\
$raku\
$rlang\
$red\
$ruby\
$rust\
$scala\
$swift\
$terraform\
$vlang\
$vagrant\
$zig\
$buf\
$nix_shell\
$conda\
$meson\
$spack\
$memory_usage\
$aws\
$gcloud\
$kubernetes\
$openstack\
$azure\
$env_var\
$crystal\
$custom\
$sudo\
$cmd_duration\
$line_break\
$jobs\
$battery\
$time\
$status\
$os\
$container\
$shell\
$character"""
[time]
disabled = false
[cmd_duration]
[kubernetes]
format = 'on [⛵ $context (\($namespace\))](dimmed green) '
disabled = false
[gcloud]
format = 'on [$symbol($project)]($style) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment