https://github.com/lukasx999/syncwd.nvim
Sync neovim cwd with shell cwd
https://github.com/lukasx999/syncwd.nvim
neovim neovim-plugin vim
Last synced: 5 months ago
JSON representation
Sync neovim cwd with shell cwd
- Host: GitHub
- URL: https://github.com/lukasx999/syncwd.nvim
- Owner: lukasx999
- License: mit
- Created: 2024-07-27T23:22:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T10:00:11.000Z (over 1 year ago)
- Last Synced: 2025-10-26T17:49:01.038Z (8 months ago)
- Topics: neovim, neovim-plugin, vim
- Language: Lua
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changecwd.sh
- License: LICENSE
Awesome Lists containing this project
README
# syncwd.nvim
## Sync Neovims working directory with the one of your shell
Normally when you start a Vim instance and navigate to another directory and exit Vim, you return to your shells CWD.
If you'd like your shells working directory to be directly synced to Neovims working directory, then this plugin does just that.
This plugin is very useful if your goal is to use a file manager such as `oil.nvim` as your primary file manager.
### Install
#### Neovim Plugin (via Lazy.nvim)
```lua
return { "lukasx999/syncwd.nvim" }
```
#### Shell script
- Save the `changecwd.sh` script to somewhere on your system (eg: `~/Scripts/syncwd/changecwd.sh`)
- Add this line to your shellrc (`~/.bashrc`, `~/.zshrc`)
```bash
# ~/.bashrc
source path/to/changecwd.sh # (source is a bashism)
# or:
. path/to/changecwd.sh
```
> **NOTE**: if syncwd is enabled within Neovim, but you have not configured your shell yet, your shell will exit after quitting vim!
### Usage
- Start Vim
- Exit Vim
> **NOTE**: Whenever your cwd gets synced when exiting, you can always use `popd` or `cd -` to go back to the previous directory before the vim session
### Configuration
```lua
return {
"lukasx999/syncwd.nvim",
config = function()
require("syncwd").setup({
init = true, -- Should syncing be enabled on startup?
})
end,
}
```
### Commands
- `:SyncwdEnable`
- `:SyncwdDisable`
- `:SyncwdToggle`
### API
```lua
local syncwd = require("syncwd")
syncwd.state()
syncwd.enable()
syncwd.disable()
syncwd.toggle()
```
### How does this work???
Right before quitting Vim, a autocmd is fired, which will write the current working directory to a temporary file. (`/tmp/syncwd_cwd`)
Then it will get the PID of its parent process. (which is the shell that it was started from)
After that, a signal, `SIGUSR1` (user defined signal) is sent to said pid.
The shell script, sourced in your `shellrc` then sets up a `trap` for said signal, which will then `pushd` into the cwd from `/tmp/syncwd_cwd`.