mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-04-08 21:10:36 +00:00
Merge d089dfb841
into fa396ad771
This commit is contained in:
commit
c2e499453b
30
plugins/pathfmt/README.md
Normal file
30
plugins/pathfmt/README.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
## Pathfmt plugin
|
||||
|
||||
This plugin adds current path information (ex: `~/Downloads/images/...`) into your terminal.
|
||||
|
||||
To use it, add `pathfmt` to the plugins array of your zshrc file:
|
||||
```
|
||||
plugins=(... pathfmt ...)
|
||||
```
|
||||
|
||||
### Configuration (required)
|
||||
Add these into your zshrc file:
|
||||
```
|
||||
#options = absolute/user/host
|
||||
PATHFMT_MODE="user"
|
||||
RPROMPT='$(path_format)'
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Things to Note:
|
||||
`PATHFMT_MODE` has three modes:
|
||||
```
|
||||
1. absolute - full path (from /).
|
||||
2. user - path from $USER/<path>
|
||||
3. host - user@machine/<path>
|
||||
```
|
||||
|
||||
|
||||
Requires [`inetutils`]([url](https://launchpad.net/ubuntu/+source/inetutils)) for the host mode
|
||||
> may show: user@unknown when not found & in host mode
|
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…
Reference in New Issue
Block a user