Skip to content

Commit b6106d9

Browse files
committed
Merge branch 'develop'
2 parents eb07592 + c3da737 commit b6106d9

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
5656
<details>
5757
<summary>Here are the latest features and updates.</summary>
5858

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

229231
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`.
230232

233+
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,
234+
235+
AGKOZAK_PROMPT_DIRTRIM_STRING=$'\u2026'
236+
237+
will replace the default three dots (`...`) with a Unicode ellipsis (``), which can free up a little screen space if your terminal font supports it.
238+
231239
## Virtual Environments
232240

233241
![Virtual environments](img/virtual_environments.gif)
@@ -692,6 +700,7 @@ Option | Default | Meaning
692700
[`AGKOZAK_PRE_PROMPT_CHAR`](#optional-single-line-prompt) | ` ` | For a single-line prompt, the character or characters to display before the prompt character
693701
[`AGKOZAK_PROMPT_DEBUG`](#asynchronous-methods) | `0` | Show debugging information
694702
[`AGKOZAK_PROMPT_DIRTRIM`](#abbreviated-paths) | `2` | Number of directory elements to display; `0` turns off directory trimming
703+
[`AGKOZAK_PROMPT_DIRTRIM_STRING`] | `...` | Ellipsis string used in directory trimming
695704
[`AGKOZAK_SHOW_STASH`](#agkozak_show_stash) | `1` | Display stashed changes
696705
[`AGKOZAK_SHOW_VIRTUALENV`](#virtual-environments) | `1` | Display virtual environments
697706
[`AGKOZAK_USER_HOST_DISPLAY`](#agkozak_user_host_display) | `1` | Display the username and hostname

agkozak-zsh-prompt.plugin.zsh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ fi
198198
: ${AGKOZAK_NAMED_DIRS:=1}
199199
# The number of path elements to display (default: 2; 0 displays the whole path)
200200
: ${AGKOZAK_PROMPT_DIRTRIM:=2}
201+
# The string to use to indicate that a path has been abbreviated (default: ...)
202+
: ${AGKOZAK_PROMPT_DIRTRIM_STRING:=...}
201203
# Whether or not to display the Git stash (default: on)
202204
: ${AGKOZAK_SHOW_STASH:=1}
203205
# Whether or not to display the username and hostname (default: on)
@@ -256,7 +258,8 @@ _agkozak_is_ssh() {
256258
# has more than a certain number of elements in its
257259
# directory tree, keep the number specified by
258260
# AGKOZAK_PROMPT_DIRTRIM (default: 2) and abbreviate the
259-
# rest with `...'. (Set AGKOZAK_PROMPT_DIRTRIM=0 to disable
261+
# rest with AGKOZAK_PROMPT_DIRTRIM_STRING (default: `...').
262+
# (Set AGKOZAK_PROMPT_DIRTRIM=0 to disable
260263
# directory trimming). For example,
261264
#
262265
# $HOME/dotfiles/polyglot/img
@@ -274,9 +277,9 @@ _agkozak_is_ssh() {
274277
# AGKOZAK_PROMPT_DEBUG
275278
# AGKOZAK_NAMED_DIRS
276279
# Arguments:
277-
# $1 [Optional] If `-v', store the function's output in
280+
# [Optional] If `-v', store the function's output in
278281
# psvar[2] instead of printing it to STDOUT
279-
# $2 Number of directory elements to display (default: 2)
282+
# [Optional] Number of directory elements to display (default: 2)
280283
############################################################
281284
_agkozak_prompt_dirtrim() {
282285
emulate -L zsh
@@ -292,6 +295,9 @@ _agkozak_prompt_dirtrim() {
292295
done
293296
[[ $1 -ge 0 ]] || set 2
294297

298+
# The ellipsis string to use when trimming paths (default: ...)
299+
local ellipsis=${AGKOZAK_PROMPT_DIRTRIM_STRING:-...}
300+
295301
local output
296302

297303
# Default behavior (when AGKOZAK_NAMED_DIRS is 1)
@@ -303,9 +309,9 @@ _agkozak_prompt_dirtrim() {
303309
if (( $1 )); then
304310
case $zsh_pwd in
305311
\~) output=${(%)zsh_pwd} ;;
306-
\~/*) output="${(%):-%($(( $1 + 2 ))~|~/.../%${1}~|%~)}" ;;
307-
\~*) output="${(%):-%($(( $1 + 2 ))~|${zsh_pwd%%${zsh_pwd#\~*\/}}.../%${1}~|%~)}" ;;
308-
*) output="${(%):-%($(( $1 + 1 ))/|.../%${1}d|%d)}" ;;
312+
\~/*) output="${(%):-%($(( $1 + 2 ))~|~/${ellipsis}/%${1}~|%~)}" ;;
313+
\~*) output="${(%):-%($(( $1 + 2 ))~|${zsh_pwd%%${zsh_pwd#\~*\/}}${ellipsis}/%${1}~|%~)}" ;;
314+
*) output="${(%):-%($(( $1 + 1 ))/|${ellipsis}/%${1}d|%d)}" ;;
309315
esac
310316
else
311317
output=$zsh_pwd
@@ -339,8 +345,8 @@ _agkozak_prompt_dirtrim() {
339345
(( i++ ))
340346
done
341347
case $PWD in
342-
${HOME}*) output="~/...${dir#${lopped_path}}" ;;
343-
*) output="...${PWD#${lopped_path}}" ;;
348+
${HOME}*) output="~/${ellipsis}${dir#${lopped_path}}" ;;
349+
*) output="${ellipsis}${PWD#${lopped_path}}" ;;
344350
esac
345351
fi
346352

@@ -815,14 +821,13 @@ _agkozak_preexec() {
815821
############################################################
816822
_agkozak_precmd() {
817823
emulate -L zsh
818-
(( AGKOZAK_PROMPT_DEBUG )) \
819-
&& [[ $ZSH_VERSION != 5.0.[0-2] ]] \
820-
&& setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL
824+
(( AGKOZAK_PROMPT_DEBUG )) && [[ $ZSH_VERSION != 5.0.[0-2] ]] &&
825+
setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL
821826

822827
# Calculate the time it took to run the last command
823828
psvar[8]=''
824829
psvar[9]=''
825-
if (( AGKOZAK_CMD_START_TIME )) && (( AGKOZAK_CMD_EXEC_TIME )); then
830+
if (( AGKOZAK_CMD_START_TIME && AGKOZAK_CMD_EXEC_TIME )); then
826831
local cmd_exec_time=$(( EPOCHSECONDS - AGKOZAK_CMD_START_TIME ))
827832
if (( cmd_exec_time >= AGKOZAK_CMD_EXEC_TIME )); then
828833
psvar[8]=$cmd_exec_time
@@ -887,7 +892,7 @@ _agkozak_precmd() {
887892
fi
888893

889894
# Optionally put blank lines between instances of the prompt
890-
(( AGKOZAK_BLANK_LINES )) && (( AGKOZAK[FIRST_PROMPT_PRINTED] )) && print
895+
(( AGKOZAK_BLANK_LINES && AGKOZAK[FIRST_PROMPT_PRINTED] )) && print
891896
AGKOZAK[FIRST_PROMPT_PRINTED]=1
892897

893898
# Begin to calculate the Git status

0 commit comments

Comments
 (0)