Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Dec 22, 2020
2 parents eb07592 + c3da737 commit b6106d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
<details>
<summary>Here are the latest features and updates.</summary>

- v3.9.0
- The characters used to signify path abbreviation with `AGKOZAK_PROMPT_DIRTRIM` (`...` by default) can now be overridden with `AGKOZAK_PROMPT_DIRTRIM_STRING`.
- v3.8.1 (November 23, 2020)
- WSL2 now uses the `subst-async` method, while WSL1 continues to use `usr1` for reasons of speed.
- The error message `permission denied: /proc/version` is no longer produced in `termux` on Android.
Expand Down Expand Up @@ -228,6 +230,12 @@ if you have executed

then `/var/www/html/wp-content` will appear in the prompt as `wp-content`, and `/var/www/html/wp-content/plugins/redirection/actions` will be represented as `~wp-content/.../redirection/actions`. If you prefer to have named directories displayed just like any others, set `AGKOZAK_NAMED_DIRS=0`.

If you want to use a string other than `...` to signify that a path has been abbreviated, you may specify it using `AGKOZAK_PROMPT_DIRTRIM_STRING`. For example,

AGKOZAK_PROMPT_DIRTRIM_STRING=$'\u2026'

will replace the default three dots (`...`) with a Unicode ellipsis (``), which can free up a little screen space if your terminal font supports it.

## Virtual Environments

![Virtual environments](img/virtual_environments.gif)
Expand Down Expand Up @@ -692,6 +700,7 @@ Option | Default | Meaning
[`AGKOZAK_PRE_PROMPT_CHAR`](#optional-single-line-prompt) | ` ` | For a single-line prompt, the character or characters to display before the prompt character
[`AGKOZAK_PROMPT_DEBUG`](#asynchronous-methods) | `0` | Show debugging information
[`AGKOZAK_PROMPT_DIRTRIM`](#abbreviated-paths) | `2` | Number of directory elements to display; `0` turns off directory trimming
[`AGKOZAK_PROMPT_DIRTRIM_STRING`] | `...` | Ellipsis string used in directory trimming
[`AGKOZAK_SHOW_STASH`](#agkozak_show_stash) | `1` | Display stashed changes
[`AGKOZAK_SHOW_VIRTUALENV`](#virtual-environments) | `1` | Display virtual environments
[`AGKOZAK_USER_HOST_DISPLAY`](#agkozak_user_host_display) | `1` | Display the username and hostname
Expand Down
31 changes: 18 additions & 13 deletions agkozak-zsh-prompt.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ fi
: ${AGKOZAK_NAMED_DIRS:=1}
# The number of path elements to display (default: 2; 0 displays the whole path)
: ${AGKOZAK_PROMPT_DIRTRIM:=2}
# The string to use to indicate that a path has been abbreviated (default: ...)
: ${AGKOZAK_PROMPT_DIRTRIM_STRING:=...}
# Whether or not to display the Git stash (default: on)
: ${AGKOZAK_SHOW_STASH:=1}
# Whether or not to display the username and hostname (default: on)
Expand Down Expand Up @@ -256,7 +258,8 @@ _agkozak_is_ssh() {
# has more than a certain number of elements in its
# directory tree, keep the number specified by
# AGKOZAK_PROMPT_DIRTRIM (default: 2) and abbreviate the
# rest with `...'. (Set AGKOZAK_PROMPT_DIRTRIM=0 to disable
# rest with AGKOZAK_PROMPT_DIRTRIM_STRING (default: `...').
# (Set AGKOZAK_PROMPT_DIRTRIM=0 to disable
# directory trimming). For example,
#
# $HOME/dotfiles/polyglot/img
Expand All @@ -274,9 +277,9 @@ _agkozak_is_ssh() {
# AGKOZAK_PROMPT_DEBUG
# AGKOZAK_NAMED_DIRS
# Arguments:
# $1 [Optional] If `-v', store the function's output in
# [Optional] If `-v', store the function's output in
# psvar[2] instead of printing it to STDOUT
# $2 Number of directory elements to display (default: 2)
# [Optional] Number of directory elements to display (default: 2)
############################################################
_agkozak_prompt_dirtrim() {
emulate -L zsh
Expand All @@ -292,6 +295,9 @@ _agkozak_prompt_dirtrim() {
done
[[ $1 -ge 0 ]] || set 2

# The ellipsis string to use when trimming paths (default: ...)
local ellipsis=${AGKOZAK_PROMPT_DIRTRIM_STRING:-...}

local output

# Default behavior (when AGKOZAK_NAMED_DIRS is 1)
Expand All @@ -303,9 +309,9 @@ _agkozak_prompt_dirtrim() {
if (( $1 )); then
case $zsh_pwd in
\~) output=${(%)zsh_pwd} ;;
\~/*) output="${(%):-%($(( $1 + 2 ))~|~/.../%${1}~|%~)}" ;;
\~*) output="${(%):-%($(( $1 + 2 ))~|${zsh_pwd%%${zsh_pwd#\~*\/}}.../%${1}~|%~)}" ;;
*) output="${(%):-%($(( $1 + 1 ))/|.../%${1}d|%d)}" ;;
\~/*) output="${(%):-%($(( $1 + 2 ))~|~/${ellipsis}/%${1}~|%~)}" ;;
\~*) output="${(%):-%($(( $1 + 2 ))~|${zsh_pwd%%${zsh_pwd#\~*\/}}${ellipsis}/%${1}~|%~)}" ;;
*) output="${(%):-%($(( $1 + 1 ))/|${ellipsis}/%${1}d|%d)}" ;;
esac
else
output=$zsh_pwd
Expand Down Expand Up @@ -339,8 +345,8 @@ _agkozak_prompt_dirtrim() {
(( i++ ))
done
case $PWD in
${HOME}*) output="~/...${dir#${lopped_path}}" ;;
*) output="...${PWD#${lopped_path}}" ;;
${HOME}*) output="~/${ellipsis}${dir#${lopped_path}}" ;;
*) output="${ellipsis}${PWD#${lopped_path}}" ;;
esac
fi

Expand Down Expand Up @@ -815,14 +821,13 @@ _agkozak_preexec() {
############################################################
_agkozak_precmd() {
emulate -L zsh
(( AGKOZAK_PROMPT_DEBUG )) \
&& [[ $ZSH_VERSION != 5.0.[0-2] ]] \
&& setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL
(( AGKOZAK_PROMPT_DEBUG )) && [[ $ZSH_VERSION != 5.0.[0-2] ]] &&
setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL

# Calculate the time it took to run the last command
psvar[8]=''
psvar[9]=''
if (( AGKOZAK_CMD_START_TIME )) && (( AGKOZAK_CMD_EXEC_TIME )); then
if (( AGKOZAK_CMD_START_TIME && AGKOZAK_CMD_EXEC_TIME )); then
local cmd_exec_time=$(( EPOCHSECONDS - AGKOZAK_CMD_START_TIME ))
if (( cmd_exec_time >= AGKOZAK_CMD_EXEC_TIME )); then
psvar[8]=$cmd_exec_time
Expand Down Expand Up @@ -887,7 +892,7 @@ _agkozak_precmd() {
fi

# Optionally put blank lines between instances of the prompt
(( AGKOZAK_BLANK_LINES )) && (( AGKOZAK[FIRST_PROMPT_PRINTED] )) && print
(( AGKOZAK_BLANK_LINES && AGKOZAK[FIRST_PROMPT_PRINTED] )) && print
AGKOZAK[FIRST_PROMPT_PRINTED]=1

# Begin to calculate the Git status
Expand Down

0 comments on commit b6106d9

Please sign in to comment.