These are a bundle of cool things in zsh.
Last active
May 20, 2023 10:20
-
-
Save eddy-22/eb3ad76114bfef3693e62f08fb7ee462 to your computer and use it in GitHub Desktop.
A collection of cool stuff I came across regarding ZSH.
This file contains 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 |
This file contains 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
## Main desk initialization, must be here | |
[ -n "$DESK_ENV" ] && source "$DESK_ENV" || true |
This file contains 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 zsh | |
local LAMBDA="%(?,%{$fg_bold[green]%}λ,%{$fg_bold[red]%}λ)" | |
if [[ "$USER" == "root" ]]; then USERCOLOR="red"; else USERCOLOR="yellow"; fi | |
# Git sometimes goes into a detached head state. git_prompt_info doesn't | |
# return anything in this case. So wrap it in another function and check | |
# for an empty string. | |
function check_git_prompt_info() { | |
if type git &>/dev/null && git rev-parse --git-dir > /dev/null 2>&1; then | |
if [[ -z $(git_prompt_info 2> /dev/null) ]]; then | |
echo "%{$fg[blue]%}detached-head%{$reset_color%}) $(git_prompt_status) | |
%{$fg[yellow]%}→ " | |
else | |
echo "$(git_prompt_info 2> /dev/null) $(git_prompt_status) | |
%{$fg_bold[cyan]%}→ " | |
fi | |
else | |
echo "%{$fg_bold[cyan]%}→ " | |
fi | |
} | |
function get_right_prompt() { | |
if type git &>/dev/null && git rev-parse --git-dir > /dev/null 2>&1; then | |
echo -n "$(git_prompt_short_sha)%{$reset_color%}" | |
else | |
echo -n "%{$reset_color%}" | |
fi | |
} | |
PROMPT=$'\n'$LAMBDA'\ | |
%{$fg_bold[$USERCOLOR]%}%n\ | |
%{$fg_no_bold[magenta]%}[%'${LAMBDA_MOD_N_DIR_LEVELS:-3}'~]\ | |
$(check_git_prompt_info)\ | |
%{$reset_color%}' | |
RPROMPT='$(get_right_prompt)' | |
# Format for git_prompt_info() | |
ZSH_THEME_GIT_PROMPT_PREFIX="at %{$fg[blue]%} " | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_DIRTY="" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%} ✔" | |
# Format for git_prompt_status() | |
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%}+" | |
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[blue]%}!" | |
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-" | |
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[magenta]%}>" | |
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[yellow]%}#" | |
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[cyan]%}?" | |
# Format for git_prompt_ahead() | |
ZSH_THEME_GIT_PROMPT_AHEAD=" %{$fg_bold[white]%}^" | |
# Format for git_prompt_long_sha() and git_prompt_short_sha() | |
ZSH_THEME_GIT_PROMPT_SHA_BEFORE=" %{$fg_bold[white]%}[%{$fg_bold[blue]%}" | |
ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$fg_bold[white]%}]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment