mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 01:52:31 +01:00
feat: add pathfmt plugin
This commit is contained in:
parent
f97e871c33
commit
2904446b50
2 changed files with 58 additions and 0 deletions
0
plugins/pathfmt/README.md
Normal file
0
plugins/pathfmt/README.md
Normal file
58
plugins/pathfmt/pathfmt.plugin.zsh
Normal file
58
plugins/pathfmt/pathfmt.plugin.zsh
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# provides a function `path_format` that displays the current working directory (on right side)
|
||||||
|
# in different formats based on the value of the variable PATHFMT_MODE.
|
||||||
|
#
|
||||||
|
# Supported formats:
|
||||||
|
# - absolute: full absolute path (default).
|
||||||
|
# - user: Replaces your $HOME with your username (e.g. "ubuntu/dir..").
|
||||||
|
# - host: Displays as "user@hostname:/path", using ~ for home when applicable.
|
||||||
|
#
|
||||||
|
# Configure the mode in your ~/.zshrc, e.g.:
|
||||||
|
# PATHFMT_MODE="host"
|
||||||
|
# plugins=(... pathfmt ...)
|
||||||
|
#
|
||||||
|
# and re-load config with source ~/.zshrc
|
||||||
|
|
||||||
|
|
||||||
|
# default=user
|
||||||
|
: ${PATHFMT_MODE:=user}
|
||||||
|
function path_user() {
|
||||||
|
# user in home? replace with ~/path
|
||||||
|
if [[ "$PWD" == "$HOME"* ]]; then
|
||||||
|
echo "~${PWD#$HOME}"
|
||||||
|
else
|
||||||
|
echo "$PWD"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function path_format() {
|
||||||
|
case $PATHFMT_MODE in
|
||||||
|
absolute)
|
||||||
|
#full path from /
|
||||||
|
echo "$PWD"
|
||||||
|
;;
|
||||||
|
user)
|
||||||
|
path_user
|
||||||
|
;;
|
||||||
|
host)
|
||||||
|
#*check if hostname found (requires: inetutils' hostname command)
|
||||||
|
local host
|
||||||
|
if command -v hostname >/dev/null 2>&1; then
|
||||||
|
host=$(hostname)
|
||||||
|
else
|
||||||
|
host="unknown"
|
||||||
|
fi
|
||||||
|
# path: user@hostname:path, using ~ if in home
|
||||||
|
if [[ "$PWD" == "$HOME"* ]]; then
|
||||||
|
echo "${USER}@${host}:~${PWD#$HOME}"
|
||||||
|
else
|
||||||
|
echo "${USER}@${host}:$PWD"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
#unrecognized: default fallback as user
|
||||||
|
path_user
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue