├── LICENSE ├── autojump.py ├── ranger-autojump.plugin.zsh └── readme.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Fabian Winter 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 | -------------------------------------------------------------------------------- /autojump.py: -------------------------------------------------------------------------------- 1 | import ranger.api 2 | import subprocess 3 | from ranger.api.commands import * 4 | 5 | HOOK_INIT_OLD = ranger.api.hook_init 6 | 7 | 8 | def hook_init(fm): 9 | def update_autojump(signal): 10 | subprocess.Popen(["autojump", "--add", signal.new.path]) 11 | 12 | fm.signal_bind('cd', update_autojump) 13 | HOOK_INIT_OLD(fm) 14 | 15 | 16 | ranger.api.hook_init = hook_init 17 | 18 | 19 | class j(Command): 20 | """:j 21 | Uses autojump to set the current directory. 22 | """ 23 | 24 | def execute(self): 25 | directory = subprocess.check_output(["autojump", self.arg(1)]) 26 | directory = directory.decode("utf-8", "ignore") 27 | directory = directory.rstrip('\n') 28 | self.fm.execute_console("cd -r " + directory) 29 | 30 | -------------------------------------------------------------------------------- /ranger-autojump.plugin.zsh: -------------------------------------------------------------------------------- 1 | # Add a `r` function to zsh that opens ranger either at the given directory or 2 | # at the one autojump suggests 3 | r() { 4 | if [ "$1" != "" ]; then 5 | if [ -d "$1" ]; then 6 | ranger "$1" 7 | elif [ -f "$1" ]; then 8 | ranger --selectfile="$1" 9 | else 10 | out="$(autojump $1)" 11 | if [ -d "$out" ]; then 12 | ranger "$out" 13 | else 14 | ranger --selectfile="$out" 15 | fi 16 | fi 17 | else 18 | ranger 19 | fi 20 | return $? 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Ranger & Autojump 2 | 3 | This plugin for ranger adds complete support for [autojump](https://github.com/wting/autojump) to [ranger](https://github.com/ranger/ranger): 4 | Whenever a new directory is opened in ranger, autojump is notified and can change the weights accordingly. 5 | Using `:j` you can use autojump to jump to a directory. This is made even better by adding `map cj console j%space` to your `rc.conf`. Thus typing `cj dirname` will let you jump to dirname. 6 | 7 | As an added bonus, there is a zsh plugin introducing a new function called `r`. Without arguments, it just opens ranger. If you supply an argument that is a directory, ranger is opened in that directory. But if you supply anything else as an argument, `autojump` is called with the argument and `ranger` is opened there 🧙 8 | 9 | If you want similar functionality for [zoxide](https://github.com/ajeetdsouza/zoxide), you can try [ranger-zoxide](https://github.com/fdw/ranger-zoxide). 10 | 11 | # Maintenance Mode 12 | As autojump seems to be unmaintained and there's not really any features missing, this repo exists as-is. I will still look at PRs and issues, but don't expect too much. 13 | 14 | If you want similar functionality for [zoxide](https://github.com/ajeetdsouza/zoxide), you can try [ranger-zoxide](https://github.com/fdw/ranger-zoxide). 15 | 16 | # Installation 17 | ### Ranger plugin 18 | - Copy `autojump.py` to `${XDG_CONFIG_HOME}/ranger/plugins`. 19 | - Add the following mapping to your `rc.conf` for convenience: 20 | ``` 21 | map cj console j%space 22 | ``` 23 | 24 | ### vim plugin (optional extra) 25 | - To use autojump with vim, the [autojump.vim](https://github.com/trotter/autojump.vim) plugin can be installed. This can also be integrated with ZSH as shown below. 26 | 27 | ### zsh plugin 28 | - Install the zsh plugin using your favorite plugin manager, e.g.: 29 | - [zgenom](https://github.com/jandamm/zgenom): 30 | - `zgenom load fdw/ranger_autojump` 31 | - [antigen](https://github.com/zsh-users/antigen): 32 | - `antigen bundle fdw/ranger_autojump@main` 33 | - [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh): 34 | 1. Clone this repository into oh-my-zsh's plugin directory: 35 | ``` 36 | git clone https://github.com/fdw/ranger-autojump ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ranger-autojump 37 | ``` 38 | 2. Activate the plugin in `~/.zshrc`: 39 | ``` 40 | plugins=( [plugins...] ranger-autojump) 41 | ``` 42 | - (Optional) For vim integration add the following convenience function to your .zshrc: 43 | ``` 44 | function jvim { file="$(AUTOJUMP_DATA_DIR=~/.autojump.vim/global autojump $@)"; if [ -n "$file" ]; then vim "$file"; fi } 45 | ``` 46 | 47 | --------------------------------------------------------------------------------