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

lib: provide a prompt function for the dirstack #376

Open
wants to merge 1 commit 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
26 changes: 26 additions & 0 deletions lib/omb-prompt-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ SCM_SVN_CHAR='⑆'
SCM_NONE='NONE'
SCM_NONE_CHAR='○'

DIRSTACK_EXPAND_TILDE=${DIRSTACK_EXPAND_TILDE:=false}
DIRSTACK_LIMIT=${DIRSTACK_LIMIT:=0}

THEME_SHOW_USER_HOST=${THEME_SHOW_USER_HOST:=false}
USER_HOST_THEME_PROMPT_PREFIX=''
USER_HOST_THEME_PROMPT_SUFFIX=''
Expand Down Expand Up @@ -585,6 +588,29 @@ function aws_profile {
fi
}

function _omb_dirstack_limit {
if [[ "${DIRSTACK_EXPAND_TILDE}" = true ]]; then
dirargs="-l"
fi
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
IFS=$'\n' read -r -d '' -a DIRS < <( dirs -p ${dirargs} && printf '\0' )
else
readarray -t DIRS < <(dirs -p ${dirargs})
fi
echo "${DIRS[@]:0:${DIRSTACK_LIMIT}}"
}

function dirs_prompt {
if [[ "${DIRSTACK_LIMIT}" -gt 0 ]]; then
_omb_dirstack_limit
else
if [[ "${DIRSTACK_EXPAND_TILDE}" = true ]]; then
dirs -l
else
dirs
fi
fi
}

# Returns true if $1 is a shell function.
_omb_deprecate_function 20000 fn_exists _omb_util_function_exists
Expand Down
2 changes: 1 addition & 1 deletion themes/bakke/bakke.theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function _omb_theme_PROMPT_COMMAND() {
#PS1="${_omb_prompt_bold_teal}$(scm_char)${_omb_prompt_green}$(scm_prompt_info)${_omb_prompt_purple}$(_omb_prompt_print_ruby_env) ${_omb_prompt_olive}\h ${_omb_prompt_reset_color}in ${_omb_prompt_green}\w ${_omb_prompt_reset_color}\n${_omb_prompt_green}→${_omb_prompt_reset_color} "
#PS1="\n${_omb_prompt_purple}\h: ${_omb_prompt_reset_color} ${_omb_prompt_green}\w\n${_omb_prompt_bold_teal}$(scm_char)${_omb_prompt_green}$(scm_prompt_info) ${_omb_prompt_green}→${_omb_prompt_reset_color} "
#PS1="\n${_omb_prompt_teal}\h: ${_omb_prompt_reset_color} ${_omb_prompt_olive}\w\n${_omb_prompt_brown}$(scm_char)${_omb_prompt_brown}$(scm_prompt_info) ${_omb_prompt_green}→${_omb_prompt_reset_color} "
PS1="\n${_omb_prompt_teal}\h: ${_omb_prompt_reset_color} ${_omb_prompt_olive}\w ${_omb_prompt_green}$(scm_prompt_info)\n${_omb_prompt_reset_color}→ "
PS1="\n${_omb_prompt_teal}\h: ${_omb_prompt_reset_color} ${_omb_prompt_olive}$(dirs_prompt) ${_omb_prompt_green}$(scm_prompt_info)\n${_omb_prompt_reset_color}→ "
}

_omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND