├── LICENSE ├── README.md ├── preview.gif ├── zsh-at.plugin.zsh └── zsh-at.zsh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019, Zeyi Fan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "@" (zsh-at) 2 | ============ 3 | 4 | A zsh plugin helps you quickly jump to the working directory of other zsh sessions. 5 | 6 | Preview 7 | ------- 8 | 9 | ![preview](preview.gif) 10 | 11 | Installation 12 | ------------ 13 | 14 | ### Oh My Zsh 15 | 16 | 1. Clone this repository to `$ZSH_CUSTOM/plugins`: 17 | 18 | ``` 19 | git clone https://github.com/fanzeyi/zsh-at.git "${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-at" 20 | ``` 21 | 22 | 2. Enable this plugin in your `~/.zshrc`: 23 | 24 | ``` 25 | plugins=(... zsh-at ...) 26 | ``` 27 | 28 | ### antigen 29 | 30 | ``` 31 | antigen bundle fanzeyi/zsh-at 32 | ``` 33 | 34 | ### Manual 35 | 36 | 1. Clone this repository to some directory, e.g. `~/.zsh` 37 | 38 | ``` 39 | git clone https://github.com/fanzeyi/zsh-at.git "~/.zsh/zsh-at" 40 | ``` 41 | 42 | 2. Add the following to your `.zshrc`: 43 | 44 | ``` 45 | source ~/.zsh/zsh-at/zsh-at.zsh 46 | ``` 47 | 48 | License 49 | ------- 50 | 51 | MIT 52 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanzeyi/zsh-at/7db232f8f06c8febfd1b86c1a52a4b55b64dd83c/preview.gif -------------------------------------------------------------------------------- /zsh-at.plugin.zsh: -------------------------------------------------------------------------------- 1 | source "${0:A:h}/zsh-at.zsh" 2 | -------------------------------------------------------------------------------- /zsh-at.zsh: -------------------------------------------------------------------------------- 1 | 2 | _zsh_at_directory_list() { 3 | lsof -a -d cwd -c zsh -Fn 2>/dev/null | grep "^n" | sed "s/^n//g" | sort | uniq 4 | } 5 | 6 | _zsh_at_completion() { 7 | typeset -a cwd_list 8 | cwd_list=("${(f)$(_zsh_at_directory_list)}") 9 | typeset -a completion 10 | completion=() 11 | local path 12 | 13 | for ((i = 1; i <= $#cwd_list; i++)); do 14 | path="${(q)cwd_list[$i]}" 15 | completion+=("$i:${(q)path}") 16 | done 17 | 18 | _describe '@' completion 19 | } 20 | 21 | compdef _zsh_at_completion @ 22 | 23 | @() { 24 | typeset -a cwd_list 25 | cwd_list=("${(f)$(_zsh_at_directory_list)}") 26 | 27 | if [[ $# == 0 ]]; then 28 | nl <<< $(printf "%s\n" "${cwd_list[@]}") 29 | return 30 | fi 31 | 32 | if [[ $# != 1 || $1 -gt $#cwd_list || $1 -le 0 ]]; then 33 | echo "error: specified index is out of range" 34 | return 35 | fi 36 | 37 | local target 38 | target="${cwd_list[$1]}" 39 | 40 | echo "cd ${(q)target}" 41 | cd "$target" 42 | } 43 | --------------------------------------------------------------------------------