Skip to content

Instantly share code, notes, and snippets.

@allejo
Last active March 31, 2020 07:18
Show Gist options
  • Save allejo/463fd55e557379df9b76c7caec217148 to your computer and use it in GitHub Desktop.
Save allejo/463fd55e557379df9b76c7caec217148 to your computer and use it in GitHub Desktop.
[My zsh prompt] The logic in my .zshrc file #zsh
#
# Make zsh tab complete case insensitive
#
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
autoload -Uz compinit && compinit
#
# IntelliJ IDE Terminals
#
# Traverse up from the PWD to find the first folder that has `$1` (file or folder)
find_up() {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
intellij_project() {
# JetBrains IDEs set `TERMINAL_EMULATOR` to something that contains "JetBrains"
if [[ "$TERMINAL_EMULATOR" == JetBrains* ]]; then
projectPath=$(find_up ".idea")
projectName=$(basename "$projectPath")
relativePath=${$(pwd)#$projectPath}
if [[ ! -z "$relativePath" ]]; then
echo "[$projectName] %{$fg[yellow]%}(${relativePath#/})%{$reset_color%} "
else
echo "[$projectName] "
fi
fi
}
#
# Git Information
#
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
autoload -U colors && colors
setopt PROMPT_SUBST
PROMPT='$(intellij_project)%{$fg[cyan]%}$(parse_git_branch)%{$reset_color%}$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment