mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-20 03:02:29 +01:00
z plugin: allow usage while in sudo mode
This commit is contained in:
parent
eafd5f3252
commit
47b7959736
4 changed files with 13 additions and 7 deletions
|
|
@ -13,6 +13,7 @@
|
|||
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
|
||||
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
|
||||
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
|
||||
# set $_Z_OWNER to your username if you want use z while sudo with $HOME kept
|
||||
#
|
||||
# USE:
|
||||
# * z foo # cd to most frecent dir matching foo
|
||||
|
|
@ -36,7 +37,7 @@ _z() {
|
|||
local datafile="${_Z_DATA:-$HOME/.z}"
|
||||
|
||||
# bail out if we don't own ~/.z (we're another user but our ENV is still set)
|
||||
[ -f "$datafile" -a ! -O "$datafile" ] && return
|
||||
[ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
|
||||
|
||||
# add entries
|
||||
if [ "$1" = "--add" ]; then
|
||||
|
|
@ -54,6 +55,7 @@ _z() {
|
|||
# maintain the file
|
||||
local tempfile
|
||||
tempfile="$(mktemp "$datafile.XXXXXX")" || return
|
||||
[ -n "$_Z_OWNER" ] && chown $_Z_OWNER:$(id -ng $_Z_OWNER) $tempfile
|
||||
while read line; do
|
||||
[ -d "${line%%\|*}" ] && echo $line
|
||||
done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue