Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional host suffix on prompt #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Lambda (Mod) ZSH Theme

A ZSH theme optimized for people who use:

- Git
- Unicode-compatible fonts and terminals

Expand All @@ -10,12 +11,21 @@ A ZSH theme optimized for people who use:

## Configuring the amount of dir levels

By default only the last three directories are shown in the prompt. The amount of
levels can be configured by setting `LAMBDA_MOD_N_DIR_LEVELS` before loading the prompt:
By default only the last three directories are shown in the prompt. The amount of levels can be
configured by setting `LAMBDA_MOD_N_DIR_LEVELS` before loading the prompt:

``` zsh
```zsh
# ~/.zshrc
export LAMBDA_MOD_N_DIR_LEVELS=10

# load `lambda-mod` and `oh-my-zsh`
```

You can display the hostname after the username with a "@" separator by setting:

```zsh
# ~/.zshrc
export LAMBDA_MOD_HOST_SUF=true

# load `lambda-mod` and `oh-my-zsh`
```
31 changes: 16 additions & 15 deletions lambda-mod.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@ if [[ "$USER" == "root" ]]; then USERCOLOR="red"; else USERCOLOR="yellow"; fi
# 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)
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]%}→ "
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
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
}

HOST_SUF=$([[ "$LAMBDA_MOD_HOST_SUF" == "true" ]] && echo "@%m" || echo "")

PROMPT=$'\n'$LAMBDA'\
%{$fg_bold[$USERCOLOR]%}%n\
%{$fg_bold[$USERCOLOR]%}%n'${HOST_SUF}'\
%{$fg_no_bold[magenta]%}[%'${LAMBDA_MOD_N_DIR_LEVELS:-3}'~]\
$(check_git_prompt_info)\
%{$reset_color%}'
Expand All @@ -53,7 +55,6 @@ 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]%}]"