Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
c0b98cd6
Commit
c0b98cd6
authored
Mar 03, 2014
by
Jeff Williams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dirhistory plugin.
This plugin navigates directory history using ALT-LEFT and ALT-RIGHT.
parent
6b3c9537
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
0 deletions
+132
-0
dirhistory.plugin.zsh
plugins/dirhistory/dirhistory.plugin.zsh
+132
-0
No files found.
plugins/dirhistory/dirhistory.plugin.zsh
0 → 100644
View file @
c0b98cd6
##
# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories
# that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT.
#
dirhistory_past
=(
`
pwd
`
)
dirhistory_future
=()
export
dirhistory_past
export
dirhistory_future
export
DIRHISTORY_SIZE
=
30
# Pop the last element of dirhistory_past.
# Pass the name of the variable to return the result in.
# Returns the element if the array was not empty,
# otherwise returns empty string.
function
pop_past
()
{
eval
"
$1
='
$dirhistory_past
[
$#dirhistory_past
]'"
if
[[
$#dirhistory_past
-gt
0
]]
;
then
dirhistory_past[
$#dirhistory_past
]=()
fi
}
function
pop_future
()
{
eval
"
$1
='
$dirhistory_future
[
$#dirhistory_future
]'"
if
[[
$#dirhistory_future
-gt
0
]]
;
then
dirhistory_future[
$#dirhistory_future
]=()
fi
}
# Push a new element onto the end of dirhistory_past. If the size of the array
# is >= DIRHISTORY_SIZE, the array is shifted
function
push_past
()
{
if
[[
$#dirhistory_past
-ge
$DIRHISTORY_SIZE
]]
;
then
shift
dirhistory_past
fi
if
[[
$#dirhistory_past
-eq
0
||
$dirhistory_past
[
$#dirhistory_past
]
!=
"
$1
"
]]
;
then
dirhistory_past+
=(
$1
)
fi
}
function
push_future
()
{
if
[[
$#dirhistory_future
-ge
$DIRHISTORY_SIZE
]]
;
then
shift
dirhistory_future
fi
if
[[
$#dirhistory_future
-eq
0
||
$dirhistory_futuret
[
$#dirhistory_future
]
!=
"
$1
"
]]
;
then
dirhistory_future+
=(
$1
)
fi
}
# Called by zsh when directory changes
function
chpwd
()
{
push_past
`
pwd
`
# If DIRHISTORY_CD is not set...
if
[[
-z
"
${
DIRHISTORY_CD
+x
}
"
]]
;
then
# ... clear future.
dirhistory_future
=()
fi
}
function
dirhistory_cd
(){
DIRHISTORY_CD
=
"1"
cd
$1
unset
DIRHISTORY_CD
}
# Move backward in directory history
function
dirhistory_back
()
{
local
cw
=
""
local
d
=
""
# Last element in dirhistory_past is the cwd.
pop_past cw
if
[[
""
==
"
$cw
"
]]
;
then
# Someone overwrote our variable. Recover it.
dirhistory_past
=(
`
pwd
`
)
return
fi
pop_past d
if
[[
""
!=
"
$d
"
]]
;
then
dirhistory_cd
$d
push_future
$cw
else
push_past
$cw
fi
}
# Move forward in directory history
function
dirhistory_forward
()
{
local
d
=
""
pop_future d
if
[[
""
!=
"
$d
"
]]
;
then
dirhistory_cd
$d
push_past
$d
fi
}
# Bind keys to history navigation
function
dirhistory_zle_dirhistory_back
()
{
# Erase current line in buffer
zle kill-buffer
dirhistory_back
zle accept-line
}
function
dirhistory_zle_dirhistory_future
()
{
# Erase current line in buffer
zle kill-buffer
dirhistory_forward
zle accept-line
}
zle
-N
dirhistory_zle_dirhistory_back
# xterm in normal mode
bindkey
"
\e
[3D"
dirhistory_zle_dirhistory_back
bindkey
"
\e
[1;3D"
dirhistory_zle_dirhistory_back
# Putty:
bindkey
"
\e\e
[D"
dirhistory_zle_dirhistory_back
# GNU screen:
bindkey
"
\e
O3D"
dirhistory_zle_dirhistory_back
zle
-N
dirhistory_zle_dirhistory_future
bindkey
"
\e
[3C"
dirhistory_zle_dirhistory_future
bindkey
"
\e
[1;3C"
dirhistory_zle_dirhistory_future
bindkey
"
\e\e
[C"
dirhistory_zle_dirhistory_future
bindkey
"
\e
O3C"
dirhistory_zle_dirhistory_future
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment