Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
869eb209
Unverified
Commit
869eb209
authored
Jan 12, 2021
by
wilkis
Committed by
GitHub
Jan 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(last-working-dir): log separate `lwd`s for different SSH keys on the same user account (#9534)
Co-authored-by:
Marc Cornellà
<
hello@mcornella.com
>
parent
fae34b38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
README.md
plugins/last-working-dir/README.md
+23
-5
last-working-dir.plugin.zsh
plugins/last-working-dir/last-working-dir.plugin.zsh
+8
-6
No files found.
plugins/last-working-dir/README.md
View file @
869eb209
# last-working-dir plugin
Keeps track of the last used working directory and automatically jumps into it
for new shells, unless
:
for new shells, unless
the starting directory is not
`$HOME`
.
-
The plugin is already loaded.
-
The current
`$PWD`
is not
`$HOME`
.
Also adds
`lwd`
function to jump to the last working directory.
Also adds a
`lwd`
function to jump to the last working directory.
To use it, add
`last-working-dir`
to the plugins array in your zshrc file:
```
zsh
plugins
=(
... last-working-dir
)
```
## Features
### Use separate last-working-dir files with different SSH keys
If the same user account is used by multiple users connecting via different SSH keys, you can
configure SSH to map them to different
`SSH_USER`
s and the plugin will use separate lwd files
for each one.
Make sure that your SSH server allows environment variables. You can enable this feature
within the
`/etc/sshd/sshd_config`
file:
```
PermitUserEnvironment yes
```
Then, add
`environment="SSH_USER=<SSH_USERNAME>"`
before the SSH keys in your
`authorized_keys`
file:
```
environment="SSH_USER=a.test@example.com" ssh-ed25519 AAAAC3Nz...
```
plugins/last-working-dir/last-working-dir.plugin.zsh
View file @
869eb209
...
...
@@ -5,16 +5,18 @@ typeset -g ZSH_LAST_WORKING_DIRECTORY
autoload
-U
add-zsh-hook
add-zsh-hook chpwd chpwd_last_working_dir
chpwd_last_working_dir
()
{
if
[
"
$ZSH_SUBSHELL
"
=
0
]
;
then
local
cache_file
=
"
$ZSH_CACHE_DIR
/last-working-dir"
pwd
>
|
"
$cache_file
"
fi
# Don't run in subshells
[[
"
$ZSH_SUBSHELL
"
-eq
0
]]
||
return
0
# Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
local
cache_file
=
"
$ZSH_CACHE_DIR
/last-working-dir
${
SSH_USER
:+.
$SSH_USER
}
"
pwd
>
|
"
$cache_file
"
}
# Changes directory to the last working directory
lwd
()
{
local
cache_file
=
"
$ZSH_CACHE_DIR
/last-working-dir"
[[
-r
"
$cache_file
"
]]
&&
cd
"
$(
cat
"
$cache_file
"
)
"
# Add ".$SSH_USER" suffix to cache file if $SSH_USER is set and non-empty
local
cache_file
=
"
$ZSH_CACHE_DIR
/last-working-dir
${
SSH_USER
:+.
$SSH_USER
}
"
[[
-r
"
$cache_file
"
]]
&&
cd
"
$(
cat
"
$cache_file
"
)
"
}
# Jump to last directory automatically unless:
...
...
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