├── .gitattributes ├── .gitignore ├── .pre-commit-config.yaml ├── .travis.yml ├── AUTHORS ├── CHANGES.md ├── LICENSE ├── Makefile ├── README.md ├── bin ├── _j ├── autojump ├── autojump.bash ├── autojump.bat ├── autojump.fish ├── autojump.lua ├── autojump.sh ├── autojump.tcsh ├── autojump.zsh ├── autojump_argparse.py ├── autojump_data.py ├── autojump_match.py ├── autojump_utils.py ├── icon.png ├── j.bat ├── jc.bat ├── jco.bat └── jo.bat ├── docs ├── autojump.1 ├── body.md ├── header.md ├── install.md └── manpage_header.md ├── install.py ├── tests ├── __init__.py ├── integration │ └── __init__.py └── unit │ ├── __init__.py │ ├── autojump_match_test.py │ └── autojump_utils_test.py ├── tools └── autojump_ipython.py ├── tox.ini └── uninstall.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Ensure batch files are crlf 2 | *.bat text eol=crlf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | .coverage 3 | *.pyc 4 | __pycache__ 5 | *~ 6 | *.tar.gz 7 | *.patch 8 | .pytest_cache 9 | .tox 10 | tags 11 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: git@github.com:pre-commit/pre-commit-hooks.git 3 | rev: v1.4.0 4 | hooks: 5 | - id: autopep8-wrapper 6 | language_version: python2 7 | args: 8 | - --in-place 9 | - --aggressive 10 | - --aggressive 11 | - --ignore=E731 12 | - --max-line-length=131 13 | - id: check-added-large-files 14 | language_version: python2 15 | - id: check-ast 16 | language_version: python2 17 | - id: check-case-conflict 18 | language_version: python2 19 | - id: check-docstring-first 20 | language_version: python2 21 | - id: debug-statements 22 | language_version: python2 23 | - id: double-quote-string-fixer 24 | language_version: python2 25 | - id: end-of-file-fixer 26 | language_version: python2 27 | exclude_types: [batch, lua] 28 | - id: fix-encoding-pragma 29 | language_version: python2 30 | - id: flake8 31 | language_version: python2 32 | args: 33 | - --max-complexity=10 34 | - --max-line-length=131 35 | - --ignore=E402,E731 36 | - --exclude=bin/autojump_argparse.py 37 | - id: name-tests-test 38 | language_version: python2 39 | - id: requirements-txt-fixer 40 | language_version: python2 41 | - id: trailing-whitespace 42 | language_version: python2 43 | - repo: git@github.com:asottile/reorder_python_imports.git 44 | rev: v1.1.1 45 | hooks: 46 | - id: reorder-python-imports 47 | language_version: python2 48 | - repo: git@github.com:asottile/add-trailing-comma 49 | rev: v0.7.0 50 | hooks: 51 | - id: add-trailing-comma 52 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 2.7 4 | 5 | env: 6 | - TOX_ENV=py26 7 | - TOX_ENV=py27 8 | - TOX_ENV=py32 9 | - TOX_ENV=py33 10 | - TOX_ENV=py34 11 | - TOX_ENV=flake8 12 | 13 | install: 14 | - pip install tox 15 | 16 | script: 17 | - tox -e $TOX_ENV 18 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The primary authors are: 2 | 3 | Joel Schaerer 4 | William Ting 5 | 6 | Here is an inevitably incomplete list of much appreciated contributors -- people 7 | who have submitted patches, reported bugs, maintained packages, and in general 8 | made autojump that much better (in no particular order): 9 | 10 | Tanguy Ortolo 11 | Thibault North 12 | Olivier Mehani 13 | Fabien Bourgeois 14 | Binh Nguyen 15 | Neeraj Verma 16 | Evan Shelhamer 17 | xiannaitong 18 | Simon Marache-Francisco 19 | Pierre Gueth 20 | Tom Parker 21 | Liyang Chang 22 | Jez Ng 23 | jjk-jacky 24 | Daniel Hahler 25 | Jui-Shan Liang 26 | Pierre Gueth 27 | Alexander Bolodurin 28 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ## Summary of release changes, see commit history for more details: 2 | ## https://github.com/wting/autojump/commits/master/ 3 | 4 | ### Release v22.4.0: 5 | - minor zsh performance improvement 6 | 7 | ### Release v22.3.0: 8 | - use colors only if stdout is a terminal 9 | - updated RedHat docs 10 | - misc bug fixes for fish and Clink versions 11 | 12 | ### Release v22.2.2: 13 | 14 | #### Backwards Incompatible 15 | 16 | - install.sh -> install.py 17 | - `--auto` option removed 18 | - `--local` option removed, defaults to local user install 19 | - `--global` option renamed to `--system` 20 | - install.py modifies autojump.sh accordingly for custom installations 21 | - it is recommended that maintainers use install.py with `--destdir` and 22 | `--prefix` accordingly. Two stage installations requires manually updating 23 | autojump.sh. 24 | - uninstall.sh -> uninstall.py 25 | - automatically removes user and system installations 26 | - now removes custom installations cleanly when passed appropriate 27 | `--destdir` and/or `--prefix` options. 28 | - new `--userdata` option to remove autojump database 29 | - all user environmental options removed: 30 | - AUTOJUMP_DATA_DIR 31 | - AUTOJUMP_IGNORE_CASE 32 | - AUTOJUMP_KEEP_SYMLINKS 33 | - misc bug fixes 34 | 35 | #### Features and Bug Fixes 36 | 37 | - fish shell support added 38 | - defaults to smartcasing 39 | - If any uppercase characters are detected, then search is case sensitive. 40 | Otherwise searches default to case insensitive. 41 | - defaults to symlinks 42 | - symlinks are not resolved to real path and thus results in duplicate 43 | database entries but ensuring that short paths will be used 44 | - autojump now uses ~/Library/autojump for storing data on OS X instead of 45 | incorrectly using Linux's $XDG_DATA_HOME. Existing data should automatically 46 | be migrated to the new location. 47 | - Past behavior jumped to the highest weight database entry when not passed any 48 | arguments. The new behavior is to stay in the current directory. 49 | 50 | 51 | ### Release v21.6.8: 52 | 53 | - fix --increase and --decrease options 54 | - heavy refactoring 55 | - remove unused unit tests 56 | 57 | ### Release v21.5.8: 58 | 59 | - fix security bug: http://www.openwall.com/lists/oss-security/2013/04/25/14 60 | - minor documentation updates, optimization performances, bug fixes 61 | 62 | ### Release v21.5.1: 63 | 64 | - add options to manually increase or decrease weight of the current directory 65 | with --increase or --decrease 66 | - add `_j` back, necessary for zsh tab completion 67 | 68 | ### Release v21.4.2: 69 | 70 | - add options to open file explorer windows with `jo`, `jco` which maps to jump 71 | open, jump child open. 72 | - remove `_j` 73 | 74 | ### Release v21.3.0: 75 | 76 | - `jumpapplet` removed. 77 | - performance improvements when using network mounts (e.g. sshfs) 78 | 79 | ### Release v21.2.0: 80 | 81 | - Add `jc` command (jump child). Jumps to a subdirectory of the current working 82 | directory. 83 | 84 | ### Release v21.1.0: 85 | 86 | - install.sh is rewritten to add support for --path and --destdir options, 87 | making it easier for package maintainers to install autojump specifically into 88 | certain locations. Thanks to jjk-jacky for his contributions. 89 | 90 | ### Release v21.0.0: 91 | 92 | - Switch to semantic versioning (http://semver.org/): major.minor.micro 93 | - Migration code for v17 or older users has been removed. 94 | 95 | During testing, it was apparent that the migration code wasn't working to 96 | begin with. The major distros (Debian, RedHat) have already moved to v18+ 97 | for LTS. Rolling release distros and Homebrew / Macports are regularly kept 98 | up to date. 99 | 100 | Users upgrading from v17 or older will start with a new database. 101 | 102 | - Approximate matching introduced. Matching priority is now: 103 | 104 | 1. exact match 105 | 2. case insensitive match 106 | 3. approximate match 107 | 108 | - The `j` function now accepts autojump arguments (e.g. --help, --stat). 109 | 110 | As a result, the `jumpstat` alias is now removed. The preferred method is `j 111 | --stat` or `j -s`. Consequently, autojump cannot jump to directories 112 | beginning with a hyphen '-'. 113 | 114 | - Always use case insensitive search with AUTOJUMP_IGNORE_CASE=1 115 | 116 | As mentioned earlier, normal priority is to prefer exact match and then 117 | check for case insensitive match. For users who prefer case insensitivity 118 | can now modify the program behavior. 119 | 120 | - Prevent database decay with AUTOJUMP_KEEP_ALL_ENTRIES=1 121 | 122 | The database is regularly trimmed for performance reasons. However users can 123 | prevent database maintenance with the above environmental variable. 124 | 125 | - ZSH tab completion fixed. 126 | 127 | ZSH behavior now matches Bash behavior. However it requires the `compinit` 128 | module to be loaded. Add the following line to ~/.zshrc: 129 | 130 | autoload -U compinit; compinit 131 | 132 | To use type: 133 | 134 | j 135 | 136 | A menu showing the top database entries will be displayed. Type in any 137 | number followed by to complete the entry. 138 | 139 | - Database entry weight growth changed form linear to logarithmic scale. 140 | 141 | A combination of low total weight ceiling and linear growth resulted in a 142 | few, commonly used directories to be responsible for 50%+ of the total 143 | database weight. This caused unnecessary trimming of long tail entries. 144 | 145 | Switching to logarithmic growth combined with regular decay meant that 146 | commonly used directories still climbed database ranking appropriately with 147 | a more even weight distribution. 148 | 149 | - Vendorize argparse so now Python v2.6+ is supported (from v2.7). 150 | - Unit testing suite added. 151 | - Miscellaneous refactoring, bug fixes, documentation updates. 152 | 153 | ### Release v20.0.0: 154 | 155 | - Python versions supported is now v2.7+ and v3.2+ due to rewrite using 156 | argparse. 157 | 158 | - Man page and --help has been overhauled to provide better documentation and 159 | usage scenarios. 160 | 161 | - Installation scripts now act dependent on current environmental settings. 162 | 163 | If run as root, will do a global install. Installation script also detects 164 | which version to install (bash or zsh) dependent on $SHELL. Both of these 165 | behaviors can be overrode using --local/--global or --bash/--zsh arguments. 166 | 167 | - Uninstallation script added, will remove both global and local installations 168 | but ignores database. 169 | 170 | - Allow symlink database entries with AUTOJUMP_KEEP_SYMLINKS=1 171 | 172 | Normally symlinks are resolved to full path to prevent duplicate database 173 | entries. However users who prefer symlink paths can modify behavior with the 174 | above environmental variable. 175 | 176 | - This ChangeLog added to better help package maintainers keep track of changes 177 | between releases. 178 | 179 | - Miscellaneous bug fixes. 180 | 181 | ### Release v19.0.0: 182 | 183 | - prototype `cp` and `mv` directory tab completion 184 | - Debian post-installation instructions 185 | - minor Mac OS X fixes 186 | 187 | ### Release v18.0.0: 188 | 189 | - add automated version numbering 190 | - performance tweaks to reduce filesystem checks 191 | - add local installation option 192 | - unicode fixes 193 | - ugly fixes for Python 3 194 | - migrate to new database format 195 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | autojump is free software: you can redistribute it and/or modify 2 | it under the terms of the GNU General Public License as published by 3 | the Free Software Foundation, either version 3 of the License, or 4 | (at your option) any later version. 5 | 6 | autojump is distributed in the hope that it will be useful, 7 | but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | full GNU General Public License below for more details. 10 | 11 | autojump is a small tool that maintains a database of your most 12 | used directories, and finds the best match to help you jump to 13 | frequently used places. 14 | 15 | GNU GENERAL PUBLIC LICENSE 16 | Version 3, 29 June 2007 17 | 18 | Copyright (C) 2007 Free Software Foundation, Inc. 19 | Everyone is permitted to copy and distribute verbatim copies 20 | of this license document, but changing it is not allowed. 21 | 22 | Preamble 23 | 24 | The GNU General Public License is a free, copyleft license for 25 | software and other kinds of works. 26 | 27 | The licenses for most software and other practical works are designed 28 | to take away your freedom to share and change the works. By contrast, 29 | the GNU General Public License is intended to guarantee your freedom to 30 | share and change all versions of a program--to make sure it remains free 31 | software for all its users. We, the Free Software Foundation, use the 32 | GNU General Public License for most of our software; it applies also to 33 | any other work released this way by its authors. You can apply it to 34 | your programs, too. 35 | 36 | When we speak of free software, we are referring to freedom, not 37 | price. Our General Public Licenses are designed to make sure that you 38 | have the freedom to distribute copies of free software (and charge for 39 | them if you wish), that you receive source code or can get it if you 40 | want it, that you can change the software or use pieces of it in new 41 | free programs, and that you know you can do these things. 42 | 43 | To protect your rights, we need to prevent others from denying you 44 | these rights or asking you to surrender the rights. Therefore, you have 45 | certain responsibilities if you distribute copies of the software, or if 46 | you modify it: responsibilities to respect the freedom of others. 47 | 48 | For example, if you distribute copies of such a program, whether 49 | gratis or for a fee, you must pass on to the recipients the same 50 | freedoms that you received. You must make sure that they, too, receive 51 | or can get the source code. And you must show them these terms so they 52 | know their rights. 53 | 54 | Developers that use the GNU GPL protect your rights with two steps: 55 | (1) assert copyright on the software, and (2) offer you this License 56 | giving you legal permission to copy, distribute and/or modify it. 57 | 58 | For the developers' and authors' protection, the GPL clearly explains 59 | that there is no warranty for this free software. For both users' and 60 | authors' sake, the GPL requires that modified versions be marked as 61 | changed, so that their problems will not be attributed erroneously to 62 | authors of previous versions. 63 | 64 | Some devices are designed to deny users access to install or run 65 | modified versions of the software inside them, although the manufacturer 66 | can do so. This is fundamentally incompatible with the aim of 67 | protecting users' freedom to change the software. The systematic 68 | pattern of such abuse occurs in the area of products for individuals to 69 | use, which is precisely where it is most unacceptable. Therefore, we 70 | have designed this version of the GPL to prohibit the practice for those 71 | products. If such problems arise substantially in other domains, we 72 | stand ready to extend this provision to those domains in future versions 73 | of the GPL, as needed to protect the freedom of users. 74 | 75 | Finally, every program is threatened constantly by software patents. 76 | States should not allow patents to restrict development and use of 77 | software on general-purpose computers, but in those that do, we wish to 78 | avoid the special danger that patents applied to a free program could 79 | make it effectively proprietary. To prevent this, the GPL assures that 80 | patents cannot be used to render the program non-free. 81 | 82 | The precise terms and conditions for copying, distribution and 83 | modification follow. 84 | 85 | TERMS AND CONDITIONS 86 | 87 | 0. Definitions. 88 | 89 | "This License" refers to version 3 of the GNU General Public License. 90 | 91 | "Copyright" also means copyright-like laws that apply to other kinds of 92 | works, such as semiconductor masks. 93 | 94 | "The Program" refers to any copyrightable work licensed under this 95 | License. Each licensee is addressed as "you". "Licensees" and 96 | "recipients" may be individuals or organizations. 97 | 98 | To "modify" a work means to copy from or adapt all or part of the work 99 | in a fashion requiring copyright permission, other than the making of an 100 | exact copy. The resulting work is called a "modified version" of the 101 | earlier work or a work "based on" the earlier work. 102 | 103 | A "covered work" means either the unmodified Program or a work based 104 | on the Program. 105 | 106 | To "propagate" a work means to do anything with it that, without 107 | permission, would make you directly or secondarily liable for 108 | infringement under applicable copyright law, except executing it on a 109 | computer or modifying a private copy. Propagation includes copying, 110 | distribution (with or without modification), making available to the 111 | public, and in some countries other activities as well. 112 | 113 | To "convey" a work means any kind of propagation that enables other 114 | parties to make or receive copies. Mere interaction with a user through 115 | a computer network, with no transfer of a copy, is not conveying. 116 | 117 | An interactive user interface displays "Appropriate Legal Notices" 118 | to the extent that it includes a convenient and prominently visible 119 | feature that (1) displays an appropriate copyright notice, and (2) 120 | tells the user that there is no warranty for the work (except to the 121 | extent that warranties are provided), that licensees may convey the 122 | work under this License, and how to view a copy of this License. If 123 | the interface presents a list of user commands or options, such as a 124 | menu, a prominent item in the list meets this criterion. 125 | 126 | 1. Source Code. 127 | 128 | The "source code" for a work means the preferred form of the work 129 | for making modifications to it. "Object code" means any non-source 130 | form of a work. 131 | 132 | A "Standard Interface" means an interface that either is an official 133 | standard defined by a recognized standards body, or, in the case of 134 | interfaces specified for a particular programming language, one that 135 | is widely used among developers working in that language. 136 | 137 | The "System Libraries" of an executable work include anything, other 138 | than the work as a whole, that (a) is included in the normal form of 139 | packaging a Major Component, but which is not part of that Major 140 | Component, and (b) serves only to enable use of the work with that 141 | Major Component, or to implement a Standard Interface for which an 142 | implementation is available to the public in source code form. A 143 | "Major Component", in this context, means a major essential component 144 | (kernel, window system, and so on) of the specific operating system 145 | (if any) on which the executable work runs, or a compiler used to 146 | produce the work, or an object code interpreter used to run it. 147 | 148 | The "Corresponding Source" for a work in object code form means all 149 | the source code needed to generate, install, and (for an executable 150 | work) run the object code and to modify the work, including scripts to 151 | control those activities. However, it does not include the work's 152 | System Libraries, or general-purpose tools or generally available free 153 | programs which are used unmodified in performing those activities but 154 | which are not part of the work. For example, Corresponding Source 155 | includes interface definition files associated with source files for 156 | the work, and the source code for shared libraries and dynamically 157 | linked subprograms that the work is specifically designed to require, 158 | such as by intimate data communication or control flow between those 159 | subprograms and other parts of the work. 160 | 161 | The Corresponding Source need not include anything that users 162 | can regenerate automatically from other parts of the Corresponding 163 | Source. 164 | 165 | The Corresponding Source for a work in source code form is that 166 | same work. 167 | 168 | 2. Basic Permissions. 169 | 170 | All rights granted under this License are granted for the term of 171 | copyright on the Program, and are irrevocable provided the stated 172 | conditions are met. This License explicitly affirms your unlimited 173 | permission to run the unmodified Program. The output from running a 174 | covered work is covered by this License only if the output, given its 175 | content, constitutes a covered work. This License acknowledges your 176 | rights of fair use or other equivalent, as provided by copyright law. 177 | 178 | You may make, run and propagate covered works that you do not 179 | convey, without conditions so long as your license otherwise remains 180 | in force. You may convey covered works to others for the sole purpose 181 | of having them make modifications exclusively for you, or provide you 182 | with facilities for running those works, provided that you comply with 183 | the terms of this License in conveying all material for which you do 184 | not control copyright. Those thus making or running the covered works 185 | for you must do so exclusively on your behalf, under your direction 186 | and control, on terms that prohibit them from making any copies of 187 | your copyrighted material outside their relationship with you. 188 | 189 | Conveying under any other circumstances is permitted solely under 190 | the conditions stated below. Sublicensing is not allowed; section 10 191 | makes it unnecessary. 192 | 193 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 194 | 195 | No covered work shall be deemed part of an effective technological 196 | measure under any applicable law fulfilling obligations under article 197 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 198 | similar laws prohibiting or restricting circumvention of such 199 | measures. 200 | 201 | When you convey a covered work, you waive any legal power to forbid 202 | circumvention of technological measures to the extent such circumvention 203 | is effected by exercising rights under this License with respect to 204 | the covered work, and you disclaim any intention to limit operation or 205 | modification of the work as a means of enforcing, against the work's 206 | users, your or third parties' legal rights to forbid circumvention of 207 | technological measures. 208 | 209 | 4. Conveying Verbatim Copies. 210 | 211 | You may convey verbatim copies of the Program's source code as you 212 | receive it, in any medium, provided that you conspicuously and 213 | appropriately publish on each copy an appropriate copyright notice; 214 | keep intact all notices stating that this License and any 215 | non-permissive terms added in accord with section 7 apply to the code; 216 | keep intact all notices of the absence of any warranty; and give all 217 | recipients a copy of this License along with the Program. 218 | 219 | You may charge any price or no price for each copy that you convey, 220 | and you may offer support or warranty protection for a fee. 221 | 222 | 5. Conveying Modified Source Versions. 223 | 224 | You may convey a work based on the Program, or the modifications to 225 | produce it from the Program, in the form of source code under the 226 | terms of section 4, provided that you also meet all of these conditions: 227 | 228 | a) The work must carry prominent notices stating that you modified 229 | it, and giving a relevant date. 230 | 231 | b) The work must carry prominent notices stating that it is 232 | released under this License and any conditions added under section 233 | 7. This requirement modifies the requirement in section 4 to 234 | "keep intact all notices". 235 | 236 | c) You must license the entire work, as a whole, under this 237 | License to anyone who comes into possession of a copy. This 238 | License will therefore apply, along with any applicable section 7 239 | additional terms, to the whole of the work, and all its parts, 240 | regardless of how they are packaged. This License gives no 241 | permission to license the work in any other way, but it does not 242 | invalidate such permission if you have separately received it. 243 | 244 | d) If the work has interactive user interfaces, each must display 245 | Appropriate Legal Notices; however, if the Program has interactive 246 | interfaces that do not display Appropriate Legal Notices, your 247 | work need not make them do so. 248 | 249 | A compilation of a covered work with other separate and independent 250 | works, which are not by their nature extensions of the covered work, 251 | and which are not combined with it such as to form a larger program, 252 | in or on a volume of a storage or distribution medium, is called an 253 | "aggregate" if the compilation and its resulting copyright are not 254 | used to limit the access or legal rights of the compilation's users 255 | beyond what the individual works permit. Inclusion of a covered work 256 | in an aggregate does not cause this License to apply to the other 257 | parts of the aggregate. 258 | 259 | 6. Conveying Non-Source Forms. 260 | 261 | You may convey a covered work in object code form under the terms 262 | of sections 4 and 5, provided that you also convey the 263 | machine-readable Corresponding Source under the terms of this License, 264 | in one of these ways: 265 | 266 | a) Convey the object code in, or embodied in, a physical product 267 | (including a physical distribution medium), accompanied by the 268 | Corresponding Source fixed on a durable physical medium 269 | customarily used for software interchange. 270 | 271 | b) Convey the object code in, or embodied in, a physical product 272 | (including a physical distribution medium), accompanied by a 273 | written offer, valid for at least three years and valid for as 274 | long as you offer spare parts or customer support for that product 275 | model, to give anyone who possesses the object code either (1) a 276 | copy of the Corresponding Source for all the software in the 277 | product that is covered by this License, on a durable physical 278 | medium customarily used for software interchange, for a price no 279 | more than your reasonable cost of physically performing this 280 | conveying of source, or (2) access to copy the 281 | Corresponding Source from a network server at no charge. 282 | 283 | c) Convey individual copies of the object code with a copy of the 284 | written offer to provide the Corresponding Source. This 285 | alternative is allowed only occasionally and noncommercially, and 286 | only if you received the object code with such an offer, in accord 287 | with subsection 6b. 288 | 289 | d) Convey the object code by offering access from a designated 290 | place (gratis or for a charge), and offer equivalent access to the 291 | Corresponding Source in the same way through the same place at no 292 | further charge. You need not require recipients to copy the 293 | Corresponding Source along with the object code. If the place to 294 | copy the object code is a network server, the Corresponding Source 295 | may be on a different server (operated by you or a third party) 296 | that supports equivalent copying facilities, provided you maintain 297 | clear directions next to the object code saying where to find the 298 | Corresponding Source. Regardless of what server hosts the 299 | Corresponding Source, you remain obligated to ensure that it is 300 | available for as long as needed to satisfy these requirements. 301 | 302 | e) Convey the object code using peer-to-peer transmission, provided 303 | you inform other peers where the object code and Corresponding 304 | Source of the work are being offered to the general public at no 305 | charge under subsection 6d. 306 | 307 | A separable portion of the object code, whose source code is excluded 308 | from the Corresponding Source as a System Library, need not be 309 | included in conveying the object code work. 310 | 311 | A "User Product" is either (1) a "consumer product", which means any 312 | tangible personal property which is normally used for personal, family, 313 | or household purposes, or (2) anything designed or sold for incorporation 314 | into a dwelling. In determining whether a product is a consumer product, 315 | doubtful cases shall be resolved in favor of coverage. For a particular 316 | product received by a particular user, "normally used" refers to a 317 | typical or common use of that class of product, regardless of the status 318 | of the particular user or of the way in which the particular user 319 | actually uses, or expects or is expected to use, the product. A product 320 | is a consumer product regardless of whether the product has substantial 321 | commercial, industrial or non-consumer uses, unless such uses represent 322 | the only significant mode of use of the product. 323 | 324 | "Installation Information" for a User Product means any methods, 325 | procedures, authorization keys, or other information required to install 326 | and execute modified versions of a covered work in that User Product from 327 | a modified version of its Corresponding Source. The information must 328 | suffice to ensure that the continued functioning of the modified object 329 | code is in no case prevented or interfered with solely because 330 | modification has been made. 331 | 332 | If you convey an object code work under this section in, or with, or 333 | specifically for use in, a User Product, and the conveying occurs as 334 | part of a transaction in which the right of possession and use of the 335 | User Product is transferred to the recipient in perpetuity or for a 336 | fixed term (regardless of how the transaction is characterized), the 337 | Corresponding Source conveyed under this section must be accompanied 338 | by the Installation Information. But this requirement does not apply 339 | if neither you nor any third party retains the ability to install 340 | modified object code on the User Product (for example, the work has 341 | been installed in ROM). 342 | 343 | The requirement to provide Installation Information does not include a 344 | requirement to continue to provide support service, warranty, or updates 345 | for a work that has been modified or installed by the recipient, or for 346 | the User Product in which it has been modified or installed. Access to a 347 | network may be denied when the modification itself materially and 348 | adversely affects the operation of the network or violates the rules and 349 | protocols for communication across the network. 350 | 351 | Corresponding Source conveyed, and Installation Information provided, 352 | in accord with this section must be in a format that is publicly 353 | documented (and with an implementation available to the public in 354 | source code form), and must require no special password or key for 355 | unpacking, reading or copying. 356 | 357 | 7. Additional Terms. 358 | 359 | "Additional permissions" are terms that supplement the terms of this 360 | License by making exceptions from one or more of its conditions. 361 | Additional permissions that are applicable to the entire Program shall 362 | be treated as though they were included in this License, to the extent 363 | that they are valid under applicable law. If additional permissions 364 | apply only to part of the Program, that part may be used separately 365 | under those permissions, but the entire Program remains governed by 366 | this License without regard to the additional permissions. 367 | 368 | When you convey a copy of a covered work, you may at your option 369 | remove any additional permissions from that copy, or from any part of 370 | it. (Additional permissions may be written to require their own 371 | removal in certain cases when you modify the work.) You may place 372 | additional permissions on material, added by you to a covered work, 373 | for which you have or can give appropriate copyright permission. 374 | 375 | Notwithstanding any other provision of this License, for material you 376 | add to a covered work, you may (if authorized by the copyright holders of 377 | that material) supplement the terms of this License with terms: 378 | 379 | a) Disclaiming warranty or limiting liability differently from the 380 | terms of sections 15 and 16 of this License; or 381 | 382 | b) Requiring preservation of specified reasonable legal notices or 383 | author attributions in that material or in the Appropriate Legal 384 | Notices displayed by works containing it; or 385 | 386 | c) Prohibiting misrepresentation of the origin of that material, or 387 | requiring that modified versions of such material be marked in 388 | reasonable ways as different from the original version; or 389 | 390 | d) Limiting the use for publicity purposes of names of licensors or 391 | authors of the material; or 392 | 393 | e) Declining to grant rights under trademark law for use of some 394 | trade names, trademarks, or service marks; or 395 | 396 | f) Requiring indemnification of licensors and authors of that 397 | material by anyone who conveys the material (or modified versions of 398 | it) with contractual assumptions of liability to the recipient, for 399 | any liability that these contractual assumptions directly impose on 400 | those licensors and authors. 401 | 402 | All other non-permissive additional terms are considered "further 403 | restrictions" within the meaning of section 10. If the Program as you 404 | received it, or any part of it, contains a notice stating that it is 405 | governed by this License along with a term that is a further 406 | restriction, you may remove that term. If a license document contains 407 | a further restriction but permits relicensing or conveying under this 408 | License, you may add to a covered work material governed by the terms 409 | of that license document, provided that the further restriction does 410 | not survive such relicensing or conveying. 411 | 412 | If you add terms to a covered work in accord with this section, you 413 | must place, in the relevant source files, a statement of the 414 | additional terms that apply to those files, or a notice indicating 415 | where to find the applicable terms. 416 | 417 | Additional terms, permissive or non-permissive, may be stated in the 418 | form of a separately written license, or stated as exceptions; 419 | the above requirements apply either way. 420 | 421 | 8. Termination. 422 | 423 | You may not propagate or modify a covered work except as expressly 424 | provided under this License. Any attempt otherwise to propagate or 425 | modify it is void, and will automatically terminate your rights under 426 | this License (including any patent licenses granted under the third 427 | paragraph of section 11). 428 | 429 | However, if you cease all violation of this License, then your 430 | license from a particular copyright holder is reinstated (a) 431 | provisionally, unless and until the copyright holder explicitly and 432 | finally terminates your license, and (b) permanently, if the copyright 433 | holder fails to notify you of the violation by some reasonable means 434 | prior to 60 days after the cessation. 435 | 436 | Moreover, your license from a particular copyright holder is 437 | reinstated permanently if the copyright holder notifies you of the 438 | violation by some reasonable means, this is the first time you have 439 | received notice of violation of this License (for any work) from that 440 | copyright holder, and you cure the violation prior to 30 days after 441 | your receipt of the notice. 442 | 443 | Termination of your rights under this section does not terminate the 444 | licenses of parties who have received copies or rights from you under 445 | this License. If your rights have been terminated and not permanently 446 | reinstated, you do not qualify to receive new licenses for the same 447 | material under section 10. 448 | 449 | 9. Acceptance Not Required for Having Copies. 450 | 451 | You are not required to accept this License in order to receive or 452 | run a copy of the Program. Ancillary propagation of a covered work 453 | occurring solely as a consequence of using peer-to-peer transmission 454 | to receive a copy likewise does not require acceptance. However, 455 | nothing other than this License grants you permission to propagate or 456 | modify any covered work. These actions infringe copyright if you do 457 | not accept this License. Therefore, by modifying or propagating a 458 | covered work, you indicate your acceptance of this License to do so. 459 | 460 | 10. Automatic Licensing of Downstream Recipients. 461 | 462 | Each time you convey a covered work, the recipient automatically 463 | receives a license from the original licensors, to run, modify and 464 | propagate that work, subject to this License. You are not responsible 465 | for enforcing compliance by third parties with this License. 466 | 467 | An "entity transaction" is a transaction transferring control of an 468 | organization, or substantially all assets of one, or subdividing an 469 | organization, or merging organizations. If propagation of a covered 470 | work results from an entity transaction, each party to that 471 | transaction who receives a copy of the work also receives whatever 472 | licenses to the work the party's predecessor in interest had or could 473 | give under the previous paragraph, plus a right to possession of the 474 | Corresponding Source of the work from the predecessor in interest, if 475 | the predecessor has it or can get it with reasonable efforts. 476 | 477 | You may not impose any further restrictions on the exercise of the 478 | rights granted or affirmed under this License. For example, you may 479 | not impose a license fee, royalty, or other charge for exercise of 480 | rights granted under this License, and you may not initiate litigation 481 | (including a cross-claim or counterclaim in a lawsuit) alleging that 482 | any patent claim is infringed by making, using, selling, offering for 483 | sale, or importing the Program or any portion of it. 484 | 485 | 11. Patents. 486 | 487 | A "contributor" is a copyright holder who authorizes use under this 488 | License of the Program or a work on which the Program is based. The 489 | work thus licensed is called the contributor's "contributor version". 490 | 491 | A contributor's "essential patent claims" are all patent claims 492 | owned or controlled by the contributor, whether already acquired or 493 | hereafter acquired, that would be infringed by some manner, permitted 494 | by this License, of making, using, or selling its contributor version, 495 | but do not include claims that would be infringed only as a 496 | consequence of further modification of the contributor version. For 497 | purposes of this definition, "control" includes the right to grant 498 | patent sublicenses in a manner consistent with the requirements of 499 | this License. 500 | 501 | Each contributor grants you a non-exclusive, worldwide, royalty-free 502 | patent license under the contributor's essential patent claims, to 503 | make, use, sell, offer for sale, import and otherwise run, modify and 504 | propagate the contents of its contributor version. 505 | 506 | In the following three paragraphs, a "patent license" is any express 507 | agreement or commitment, however denominated, not to enforce a patent 508 | (such as an express permission to practice a patent or covenant not to 509 | sue for patent infringement). To "grant" such a patent license to a 510 | party means to make such an agreement or commitment not to enforce a 511 | patent against the party. 512 | 513 | If you convey a covered work, knowingly relying on a patent license, 514 | and the Corresponding Source of the work is not available for anyone 515 | to copy, free of charge and under the terms of this License, through a 516 | publicly available network server or other readily accessible means, 517 | then you must either (1) cause the Corresponding Source to be so 518 | available, or (2) arrange to deprive yourself of the benefit of the 519 | patent license for this particular work, or (3) arrange, in a manner 520 | consistent with the requirements of this License, to extend the patent 521 | license to downstream recipients. "Knowingly relying" means you have 522 | actual knowledge that, but for the patent license, your conveying the 523 | covered work in a country, or your recipient's use of the covered work 524 | in a country, would infringe one or more identifiable patents in that 525 | country that you have reason to believe are valid. 526 | 527 | If, pursuant to or in connection with a single transaction or 528 | arrangement, you convey, or propagate by procuring conveyance of, a 529 | covered work, and grant a patent license to some of the parties 530 | receiving the covered work authorizing them to use, propagate, modify 531 | or convey a specific copy of the covered work, then the patent license 532 | you grant is automatically extended to all recipients of the covered 533 | work and works based on it. 534 | 535 | A patent license is "discriminatory" if it does not include within 536 | the scope of its coverage, prohibits the exercise of, or is 537 | conditioned on the non-exercise of one or more of the rights that are 538 | specifically granted under this License. You may not convey a covered 539 | work if you are a party to an arrangement with a third party that is 540 | in the business of distributing software, under which you make payment 541 | to the third party based on the extent of your activity of conveying 542 | the work, and under which the third party grants, to any of the 543 | parties who would receive the covered work from you, a discriminatory 544 | patent license (a) in connection with copies of the covered work 545 | conveyed by you (or copies made from those copies), or (b) primarily 546 | for and in connection with specific products or compilations that 547 | contain the covered work, unless you entered into that arrangement, 548 | or that patent license was granted, prior to 28 March 2007. 549 | 550 | Nothing in this License shall be construed as excluding or limiting 551 | any implied license or other defenses to infringement that may 552 | otherwise be available to you under applicable patent law. 553 | 554 | 12. No Surrender of Others' Freedom. 555 | 556 | If conditions are imposed on you (whether by court order, agreement or 557 | otherwise) that contradict the conditions of this License, they do not 558 | excuse you from the conditions of this License. If you cannot convey a 559 | covered work so as to satisfy simultaneously your obligations under this 560 | License and any other pertinent obligations, then as a consequence you may 561 | not convey it at all. For example, if you agree to terms that obligate you 562 | to collect a royalty for further conveying from those to whom you convey 563 | the Program, the only way you could satisfy both those terms and this 564 | License would be to refrain entirely from conveying the Program. 565 | 566 | 13. Use with the GNU Affero General Public License. 567 | 568 | Notwithstanding any other provision of this License, you have 569 | permission to link or combine any covered work with a work licensed 570 | under version 3 of the GNU Affero General Public License into a single 571 | combined work, and to convey the resulting work. The terms of this 572 | License will continue to apply to the part which is the covered work, 573 | but the special requirements of the GNU Affero General Public License, 574 | section 13, concerning interaction through a network will apply to the 575 | combination as such. 576 | 577 | 14. Revised Versions of this License. 578 | 579 | The Free Software Foundation may publish revised and/or new versions of 580 | the GNU General Public License from time to time. Such new versions will 581 | be similar in spirit to the present version, but may differ in detail to 582 | address new problems or concerns. 583 | 584 | Each version is given a distinguishing version number. If the 585 | Program specifies that a certain numbered version of the GNU General 586 | Public License "or any later version" applies to it, you have the 587 | option of following the terms and conditions either of that numbered 588 | version or of any later version published by the Free Software 589 | Foundation. If the Program does not specify a version number of the 590 | GNU General Public License, you may choose any version ever published 591 | by the Free Software Foundation. 592 | 593 | If the Program specifies that a proxy can decide which future 594 | versions of the GNU General Public License can be used, that proxy's 595 | public statement of acceptance of a version permanently authorizes you 596 | to choose that version for the Program. 597 | 598 | Later license versions may give you additional or different 599 | permissions. However, no additional obligations are imposed on any 600 | author or copyright holder as a result of your choosing to follow a 601 | later version. 602 | 603 | 15. Disclaimer of Warranty. 604 | 605 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 606 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 607 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 608 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 609 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 610 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 611 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 612 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 613 | 614 | 16. Limitation of Liability. 615 | 616 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 617 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 618 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 619 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 620 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 621 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 622 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 623 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 624 | SUCH DAMAGES. 625 | 626 | 17. Interpretation of Sections 15 and 16. 627 | 628 | If the disclaimer of warranty and limitation of liability provided 629 | above cannot be given local legal effect according to their terms, 630 | reviewing courts shall apply local law that most closely approximates 631 | an absolute waiver of all civil liability in connection with the 632 | Program, unless a warranty or assumption of liability accompanies a 633 | copy of the Program in return for a fee. 634 | 635 | END OF TERMS AND CONDITIONS 636 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION = $(shell grep -oE "[0-9]+\.[0-9]+\.[0-9]+" bin/autojump) 2 | TAGNAME = release-v$(VERSION) 3 | 4 | .PHONY: install 5 | install: 6 | ./install.py 7 | 8 | .PHONY: uninstall 9 | uninstall: 10 | ./uninstall.py 11 | 12 | .PHONY: docs 13 | docs: 14 | @echo "% autojump(1) ${TAGNAME}" >docs/manpage_header.md 15 | @echo "%" >>docs/manpage_header.md 16 | @echo "% $(shell \date +%Y-%m-%d)" >>docs/manpage_header.md 17 | pandoc -s -w man docs/manpage_header.md docs/header.md docs/body.md -o docs/autojump.1 18 | pandoc -s -w markdown docs/header.md docs/install.md docs/body.md -o README.md 19 | 20 | .PHONY: lint 21 | lint: pre-commit 22 | @tox -e pre-commit -- run --all-files 23 | 24 | .PHONY: pre-commit 25 | pre-commit: 26 | @tox -e pre-commit -- install -f --install-hooks 27 | 28 | .PHONY: release 29 | release: docs 30 | # Check for tag existence 31 | # git describe release-$(VERSION) 2>&1 >/dev/null || exit 1 32 | 33 | # Modify autojump with version 34 | ./tools/git-version.sh $(TAGNAME) 35 | 36 | # Commit the version change 37 | git commit -m "version numbering" ./bin/autojump 38 | 39 | # Create tag 40 | git tag -a $(TAGNAME) 41 | 42 | # Create tagged archive 43 | git archive --format=tar --prefix autojump_v$(VERSION)/ $(TAGNAME) | gzip > autojump_v$(VERSION).tar.gz 44 | sha1sum autojump_v$(VERSION).tar.gz 45 | 46 | .PHONY: tar 47 | tar: 48 | # Create tagged archive 49 | git archive --format=tar --prefix autojump_v$(VERSION)/ $(TAGNAME) | gzip > autojump_v$(VERSION).tar.gz 50 | sha1sum autojump_v$(VERSION).tar.gz 51 | 52 | .PHONY: test 53 | test: pre-commit 54 | @tox 55 | 56 | .PHONY: test-xfail 57 | test-xfail: pre-commit 58 | @tox -- --runxfail 59 | 60 | .PHONY: test-fast 61 | test-fast: pre-commit 62 | @tox -e py27 63 | 64 | .PHONY: clean 65 | clean: 66 | @find . -type f -iname '*.py[co]' -delete 67 | @find . -type d -iname '__pycache__' -delete 68 | @rm -fr .tox 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NAME 2 | ---- 3 | 4 | autojump - a faster way to navigate your filesystem 5 | 6 | DESCRIPTION 7 | ----------- 8 | 9 | autojump is a faster way to navigate your filesystem. It works by 10 | maintaining a database of the directories you use the most from the 11 | command line. 12 | 13 | *Directories must be visited first before they can be jumped to.* 14 | 15 | USAGE 16 | ----- 17 | 18 | `j` is a convenience wrapper function around `autojump`. Any option that 19 | can be used with `autojump` can be used with `j` and vice versa. 20 | 21 | - Jump To A Directory That Contains `foo`: 22 | 23 | j foo 24 | 25 | - Jump To A Directory That Contains `foo`, Preferring Child Directories: 26 | 27 | You can prioritize child directories over matches in the databases via 28 | 29 | jc foo 30 | 31 | - Open File Manager To Directories (instead of jumping): 32 | 33 | Instead of jumping to a directory, you can open a file explorer 34 | window (Mac Finder, Windows Explorer, GNOME Nautilus, etc.) to the 35 | directory instead. 36 | 37 | jo music 38 | 39 | Opening a file manager to a child directory is also supported: 40 | 41 | jco images 42 | 43 | - Using Multiple Arguments: 44 | 45 | Let's assume the following database: 46 | 47 | 30 /home/user/mail/inbox 48 | 10 /home/user/work/inbox 49 | 50 | `j in` would jump into /home/user/mail/inbox as the higher 51 | weighted entry. However you can pass multiple arguments to autojump 52 | to prefer a different entry. In the above example, `j w in` would 53 | then change directory to /home/user/work/inbox. 54 | 55 | For more options refer to help: 56 | 57 | autojump --help 58 | 59 | INSTALLATION 60 | ------------ 61 | 62 | ### REQUIREMENTS 63 | 64 | - Python v2.6+ or Python v3.3+ 65 | - Supported shells 66 | - bash - first class support 67 | - zsh - first class support 68 | - fish - community supported 69 | - tcsh - community supported 70 | - clink - community supported 71 | - Supported platforms 72 | - Linux - first class support 73 | - OS X - first class support 74 | - Windows - community supported 75 | - BSD - community supported 76 | - Supported installation methods 77 | - source code - first class support 78 | - Debian and derivatives - first class support 79 | - ArchLinux / Gentoo / openSUSE / RedHat and derivatives - 80 | community supported 81 | - Homebrew / MacPorts - community supported 82 | 83 | Due to limited time and resources, only "first class support" items will 84 | be maintained by the primary committers. All "community supported" items 85 | will be updated based on pull requests submitted by the general public. 86 | 87 | Please continue opening issues and providing feedback for community 88 | supported items since consolidating information helps other users 89 | troubleshoot and submit enhancements and fixes. 90 | 91 | ### MANUAL 92 | 93 | Grab a copy of autojump: 94 | 95 | git clone https://github.com/wting/autojump.git 96 | 97 | Run the installation script and follow on screen instructions. 98 | 99 | cd autojump 100 | ./install.py or ./uninstall.py 101 | 102 | ### AUTOMATIC 103 | 104 | #### Linux 105 | 106 | autojump is included in the following distro repositories, please use 107 | relevant package management utilities to install (e.g. apt-get, yum, 108 | pacman, etc): 109 | 110 | - Debian, Ubuntu, Linux Mint 111 | 112 | All Debian-derived distros require manual activation for policy 113 | reasons, please see `/usr/share/doc/autojump/README.Debian`. 114 | 115 | - RedHat, Fedora, CentOS 116 | 117 | Install `autojump-zsh` for zsh, `autojump-fish` for fish, etc. 118 | 119 | - ArchLinux 120 | - Gentoo 121 | - Frugalware 122 | - Slackware 123 | 124 | #### OS X 125 | 126 | Homebrew is the recommended installation method for Mac OS X: 127 | 128 | brew install autojump 129 | 130 | MacPorts is also available: 131 | 132 | port install autojump 133 | 134 | Windows 135 | ------- 136 | 137 | Windows support is enabled by [clink](https://mridgers.github.io/clink/) 138 | which should be installed prior to installing autojump. 139 | 140 | KNOWN ISSUES 141 | ------------ 142 | 143 | - autojump does not support directories that begin with `-`. 144 | 145 | - For bash users, autojump keeps track of directories by modifying 146 | `$PROMPT_COMMAND`. Do not overwrite `$PROMPT_COMMAND`: 147 | 148 | export PROMPT_COMMAND="history -a" 149 | 150 | Instead append to the end of the existing \$PROMPT\_COMMAND: 151 | 152 | export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ;} history -a" 153 | 154 | REPORTING BUGS 155 | -------------- 156 | 157 | For any questions or issues please visit: 158 | 159 | https://github.com/wting/autojump/issues 160 | 161 | AUTHORS 162 | ------- 163 | 164 | autojump was originally written by Joël Schaerer, and currently 165 | maintained by William Ting. More contributors can be found in `AUTHORS`. 166 | 167 | COPYRIGHT 168 | --------- 169 | 170 | Copyright © 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL 171 | version 3 or later . This is free 172 | software: you are free to change and redistribute it. There is NO 173 | WARRANTY, to the extent permitted by law. 174 | -------------------------------------------------------------------------------- /bin/_j: -------------------------------------------------------------------------------- 1 | #compdef j 2 | cur=${words[2, -1]} 3 | 4 | autojump --complete ${=cur[*]} | while read i; do 5 | compadd -U "$i"; 6 | done 7 | -------------------------------------------------------------------------------- /bin/autojump: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Copyright © 2008-2012 Joel Schaerer 5 | Copyright © 2012-2016 William Ting 6 | 7 | * This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3, or (at your option) 10 | any later version. 11 | 12 | * This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | * You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | """ 21 | from __future__ import print_function 22 | 23 | import os 24 | import sys 25 | from itertools import chain 26 | from math import sqrt 27 | from operator import attrgetter 28 | from operator import itemgetter 29 | 30 | if sys.version_info[0] == 3: 31 | ifilter = filter 32 | imap = map 33 | os.getcwdu = os.getcwd 34 | else: 35 | from itertools import ifilter 36 | from itertools import imap 37 | 38 | # Vendorized argparse for Python 2.6 support 39 | from autojump_argparse import ArgumentParser 40 | 41 | # autojump is not a standard python package but rather installed as a mixed 42 | # shell + Python app with no outside dependencies (except Python). As a 43 | # consequence we use relative imports and depend on file prefixes to prevent 44 | # module conflicts. 45 | from autojump_data import dictify 46 | from autojump_data import entriefy 47 | from autojump_data import Entry 48 | from autojump_data import load 49 | from autojump_data import save 50 | from autojump_match import match_anywhere 51 | from autojump_match import match_consecutive 52 | from autojump_match import match_fuzzy 53 | from autojump_utils import first 54 | from autojump_utils import get_pwd 55 | from autojump_utils import get_tab_entry_info 56 | from autojump_utils import has_uppercase 57 | from autojump_utils import is_autojump_sourced 58 | from autojump_utils import is_osx 59 | from autojump_utils import is_windows 60 | from autojump_utils import last 61 | from autojump_utils import print_entry 62 | from autojump_utils import print_local 63 | from autojump_utils import print_tab_menu 64 | from autojump_utils import sanitize 65 | from autojump_utils import take 66 | from autojump_utils import unico 67 | 68 | VERSION = '22.5.3' 69 | FUZZY_MATCH_THRESHOLD = 0.6 70 | TAB_ENTRIES_COUNT = 9 71 | TAB_SEPARATOR = '__' 72 | 73 | 74 | def set_defaults(): 75 | config = {} 76 | 77 | if is_osx(): 78 | data_home = os.path.join(os.path.expanduser('~'), 'Library') 79 | elif is_windows(): 80 | data_home = os.getenv('APPDATA') 81 | else: 82 | data_home = os.getenv( 83 | 'XDG_DATA_HOME', 84 | os.path.join( 85 | os.path.expanduser('~'), 86 | '.local', 87 | 'share', 88 | ), 89 | ) 90 | config['data_path'] = os.path.join(data_home, 'autojump', 'autojump.txt') 91 | config['backup_path'] = os.path.join(data_home, 'autojump', 'autojump.txt.bak') 92 | 93 | return config 94 | 95 | 96 | def parse_arguments(): 97 | parser = ArgumentParser( 98 | description='Automatically jump to directory passed as an argument.', 99 | epilog='Please see autojump(1) man pages for full documentation.', 100 | ) 101 | parser.add_argument( 102 | 'directory', metavar='DIRECTORY', nargs='*', default='', 103 | help='directory to jump to', 104 | ) 105 | parser.add_argument( 106 | '-a', '--add', metavar='DIRECTORY', 107 | help='add path', 108 | ) 109 | parser.add_argument( 110 | '-i', '--increase', metavar='WEIGHT', nargs='?', type=int, 111 | const=10, default=False, 112 | help='increase current directory weight', 113 | ) 114 | parser.add_argument( 115 | '-d', '--decrease', metavar='WEIGHT', nargs='?', type=int, 116 | const=15, default=False, 117 | help='decrease current directory weight', 118 | ) 119 | parser.add_argument( 120 | '--complete', action='store_true', default=False, 121 | help='used for tab completion', 122 | ) 123 | parser.add_argument( 124 | '--purge', action='store_true', default=False, 125 | help='remove non-existent paths from database', 126 | ) 127 | parser.add_argument( 128 | '-s', '--stat', action='store_true', default=False, 129 | help='show database entries and their key weights', 130 | ) 131 | parser.add_argument( 132 | '-v', '--version', action='version', version='%(prog)s v' + 133 | VERSION, help='show version information', 134 | ) 135 | 136 | return parser.parse_args() 137 | 138 | 139 | def add_path(data, path, weight=10): 140 | """ 141 | Add a new path or increment an existing one. 142 | 143 | os.path.realpath() is not used because it's preferable to use symlinks 144 | with resulting duplicate entries in the database than a single canonical 145 | path. 146 | """ 147 | path = unico(path).rstrip(os.sep) 148 | if path == os.path.expanduser('~'): 149 | return data, Entry(path, 0) 150 | 151 | data[path] = sqrt((data.get(path, 0) ** 2) + (weight ** 2)) 152 | 153 | return data, Entry(path, data[path]) 154 | 155 | 156 | def decrease_path(data, path, weight=15): 157 | """Decrease or zero out a path.""" 158 | path = unico(path).rstrip(os.sep) 159 | data[path] = max(0, data.get(path, 0) - weight) 160 | return data, Entry(path, data[path]) 161 | 162 | 163 | def detect_smartcase(needles): 164 | """ 165 | If any needles contain an uppercase letter then use case sensitive 166 | searching. Otherwise use case insensitive searching. 167 | """ 168 | return not any(imap(has_uppercase, needles)) 169 | 170 | 171 | def find_matches(entries, needles, check_entries=True): 172 | """Return an iterator to matching entries.""" 173 | # TODO(wting|2014-02-24): replace assertion with unit test 174 | assert isinstance(needles, list), 'Needles must be a list.' 175 | ignore_case = detect_smartcase(needles) 176 | 177 | try: 178 | pwd = os.getcwdu() 179 | except OSError: 180 | pwd = None 181 | 182 | # using closure to prevent constantly hitting hdd 183 | def is_cwd(entry): 184 | return os.path.realpath(entry.path) == pwd 185 | 186 | if check_entries: 187 | path_exists = lambda entry: os.path.exists(entry.path) 188 | else: 189 | path_exists = lambda _: True 190 | 191 | data = sorted( 192 | entries, 193 | key=attrgetter('weight', 'path'), 194 | reverse=True, 195 | ) 196 | 197 | return ifilter( 198 | lambda entry: not is_cwd(entry) and path_exists(entry), 199 | chain( 200 | match_consecutive(needles, data, ignore_case), 201 | match_fuzzy(needles, data, ignore_case), 202 | match_anywhere(needles, data, ignore_case), 203 | ), 204 | ) 205 | 206 | 207 | def handle_tab_completion(needle, entries): 208 | tab_needle, tab_index, tab_path = get_tab_entry_info(needle, TAB_SEPARATOR) 209 | 210 | if tab_path: 211 | print_local(tab_path) 212 | elif tab_index: 213 | get_ith_path = lambda i, iterable: last(take(i, iterable)).path 214 | print_local(get_ith_path( 215 | tab_index, 216 | find_matches(entries, [tab_needle], check_entries=False), 217 | )) 218 | elif tab_needle: 219 | # found partial tab completion entry 220 | print_tab_menu( 221 | tab_needle, 222 | take( 223 | TAB_ENTRIES_COUNT, find_matches( 224 | entries, 225 | [tab_needle], 226 | check_entries=False, 227 | ), 228 | ), 229 | TAB_SEPARATOR, 230 | ) 231 | else: 232 | print_tab_menu( 233 | needle, 234 | take( 235 | TAB_ENTRIES_COUNT, find_matches( 236 | entries, 237 | [needle], 238 | check_entries=False, 239 | ), 240 | ), 241 | TAB_SEPARATOR, 242 | ) 243 | 244 | 245 | def purge_missing_paths(entries): 246 | """Remove non-existent paths from a list of entries.""" 247 | exists = lambda entry: os.path.exists(entry.path) 248 | return ifilter(exists, entries) 249 | 250 | 251 | def print_stats(data, data_path): 252 | for path, weight in sorted(data.items(), key=itemgetter(1)): 253 | print_entry(Entry(path, weight)) 254 | 255 | print('________________________________________\n') 256 | print('%d:\t total weight' % sum(data.values())) 257 | print('%d:\t number of entries' % len(data)) 258 | 259 | try: 260 | print_local( 261 | '%.2f:\t current directory weight' % data.get(os.getcwdu(), 0), 262 | ) 263 | except OSError: 264 | # current directory no longer exists 265 | pass 266 | 267 | print('\ndata:\t %s' % data_path) 268 | 269 | 270 | def main(args): # noqa 271 | if not is_autojump_sourced() and not is_windows(): 272 | print("Please source the correct autojump file in your shell's") 273 | print('startup file. For more information, please reinstall autojump') 274 | print('and read the post installation instructions.') 275 | return 1 276 | 277 | config = set_defaults() 278 | 279 | # all arguments are mutually exclusive 280 | if args.add: 281 | save(config, first(add_path(load(config), args.add))) 282 | elif args.complete: 283 | handle_tab_completion( 284 | needle=first(chain(sanitize(args.directory), [''])), 285 | entries=entriefy(load(config)), 286 | ) 287 | elif args.decrease: 288 | data, entry = decrease_path(load(config), get_pwd(), args.decrease) 289 | save(config, data) 290 | print_entry(entry) 291 | elif args.increase: 292 | data, entry = add_path(load(config), get_pwd(), args.increase) 293 | save(config, data) 294 | print_entry(entry) 295 | elif args.purge: 296 | old_data = load(config) 297 | new_data = dictify(purge_missing_paths(entriefy(old_data))) 298 | save(config, new_data) 299 | print('Purged %d entries.' % (len(old_data) - len(new_data))) 300 | elif args.stat: 301 | print_stats(load(config), config['data_path']) 302 | elif not args.directory: 303 | # Return best match. 304 | entries = entriefy(load(config)) 305 | print_local(first(chain( 306 | imap(attrgetter('path'), find_matches(entries, [''])), 307 | # always return a path to calling shell functions 308 | ['.'], 309 | ))) 310 | else: 311 | entries = entriefy(load(config)) 312 | needles = sanitize(args.directory) 313 | tab_needle, tab_index, tab_path = \ 314 | get_tab_entry_info(first(needles), TAB_SEPARATOR) 315 | 316 | # Handle `j foo__`, assuming first index. 317 | if not tab_path and not tab_index \ 318 | and tab_needle and needles[0] == tab_needle + TAB_SEPARATOR: 319 | tab_index = 1 320 | 321 | if tab_path: 322 | print_local(tab_path) 323 | elif tab_index: 324 | get_ith_path = lambda i, iterable: last(take(i, iterable)).path 325 | print_local( 326 | get_ith_path( 327 | tab_index, 328 | find_matches(entries, [tab_needle]), 329 | ), 330 | ) 331 | else: 332 | print_local(first(chain( 333 | imap(attrgetter('path'), find_matches(entries, needles)), 334 | # always return a path to calling shell functions 335 | ['.'], 336 | ))) 337 | 338 | return 0 339 | 340 | 341 | if __name__ == '__main__': 342 | sys.exit(main(parse_arguments())) 343 | -------------------------------------------------------------------------------- /bin/autojump.bash: -------------------------------------------------------------------------------- 1 | export AUTOJUMP_SOURCED=1 2 | 3 | # set user installation paths 4 | if [[ -d ~/.autojump/ ]]; then 5 | export PATH=~/.autojump/bin:"${PATH}" 6 | fi 7 | 8 | 9 | # set error file location 10 | if [[ "$(uname)" == "Darwin" ]]; then 11 | export AUTOJUMP_ERROR_PATH=~/Library/autojump/errors.log 12 | elif [[ -n "${XDG_DATA_HOME}" ]]; then 13 | export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/autojump/errors.log" 14 | else 15 | export AUTOJUMP_ERROR_PATH=~/.local/share/autojump/errors.log 16 | fi 17 | 18 | if [[ ! -d "$(dirname ${AUTOJUMP_ERROR_PATH})" ]]; then 19 | mkdir -p "$(dirname ${AUTOJUMP_ERROR_PATH})" 20 | fi 21 | 22 | 23 | # enable tab completion 24 | _autojump() { 25 | local cur 26 | cur=${COMP_WORDS[*]:1} 27 | comps=$(autojump --complete $cur) 28 | while read i; do 29 | COMPREPLY=("${COMPREPLY[@]}" "${i}") 30 | done </dev/null 2>>${AUTOJUMP_ERROR_PATH} &) &>/dev/null 41 | else 42 | (autojump --add "$(pwd)" >/dev/null &) &>/dev/null 43 | fi 44 | } 45 | 46 | case $PROMPT_COMMAND in 47 | *autojump*) 48 | ;; 49 | *) 50 | PROMPT_COMMAND="${PROMPT_COMMAND:+$(echo "${PROMPT_COMMAND}" | awk '{gsub(/; *$/,"")}1') ; }autojump_add_to_database" 51 | ;; 52 | esac 53 | 54 | 55 | # default autojump command 56 | j() { 57 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 58 | autojump ${@} 59 | return 60 | fi 61 | 62 | output="$(autojump ${@})" 63 | if [[ -d "${output}" ]]; then 64 | if [ -t 1 ]; then # if stdout is a terminal, use colors 65 | echo -e "\\033[31m${output}\\033[0m" 66 | else 67 | echo -e "${output}" 68 | fi 69 | cd "${output}" 70 | else 71 | echo "autojump: directory '${@}' not found" 72 | echo "\n${output}\n" 73 | echo "Try \`autojump --help\` for more information." 74 | false 75 | fi 76 | } 77 | 78 | 79 | # jump to child directory (subdirectory of current path) 80 | jc() { 81 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 82 | autojump ${@} 83 | return 84 | else 85 | j $(pwd) ${@} 86 | fi 87 | } 88 | 89 | 90 | # open autojump results in file browser 91 | jo() { 92 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 93 | autojump ${@} 94 | return 95 | fi 96 | 97 | output="$(autojump ${@})" 98 | if [[ -d "${output}" ]]; then 99 | case ${OSTYPE} in 100 | linux*) 101 | xdg-open "${output}" 102 | ;; 103 | darwin*) 104 | open "${output}" 105 | ;; 106 | cygwin) 107 | cygstart "" $(cygpath -w -a ${output}) 108 | ;; 109 | *) 110 | echo "Unknown operating system: ${OSTYPE}." 1>&2 111 | ;; 112 | esac 113 | else 114 | echo "autojump: directory '${@}' not found" 115 | echo "\n${output}\n" 116 | echo "Try \`autojump --help\` for more information." 117 | false 118 | fi 119 | } 120 | 121 | 122 | # open autojump results (child directory) in file browser 123 | jco() { 124 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 125 | autojump ${@} 126 | return 127 | else 128 | jo $(pwd) ${@} 129 | fi 130 | } 131 | -------------------------------------------------------------------------------- /bin/autojump.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | python "%~dp0\autojump" %* 3 | -------------------------------------------------------------------------------- /bin/autojump.fish: -------------------------------------------------------------------------------- 1 | set -gx AUTOJUMP_SOURCED 1 2 | 3 | # set user installation path 4 | if test -d ~/.autojump 5 | set -x PATH ~/.autojump/bin $PATH 6 | end 7 | 8 | # Set ostype, if not set 9 | if not set -q OSTYPE 10 | set -gx OSTYPE (bash -c 'echo ${OSTYPE}') 11 | end 12 | 13 | 14 | # enable tab completion 15 | complete -x -c j -a '(autojump --complete (commandline -t))' 16 | 17 | 18 | # set error file location 19 | if test (uname) = "Darwin" 20 | set -gx AUTOJUMP_ERROR_PATH ~/Library/autojump/errors.log 21 | else if test -d "$XDG_DATA_HOME" 22 | set -gx AUTOJUMP_ERROR_PATH $XDG_DATA_HOME/autojump/errors.log 23 | else 24 | set -gx AUTOJUMP_ERROR_PATH ~/.local/share/autojump/errors.log 25 | end 26 | 27 | if test ! -d (dirname $AUTOJUMP_ERROR_PATH) 28 | mkdir -p (dirname $AUTOJUMP_ERROR_PATH) 29 | end 30 | 31 | 32 | # change pwd hook 33 | function __aj_add --on-variable PWD 34 | status --is-command-substitution; and return 35 | autojump --add (pwd) >/dev/null 2>>$AUTOJUMP_ERROR_PATH & 36 | end 37 | 38 | 39 | # misc helper functions 40 | function __aj_err 41 | # TODO(ting|#247): set error file location 42 | echo -e $argv 1>&2; false 43 | end 44 | 45 | # default autojump command 46 | function j 47 | switch "$argv" 48 | case '-*' '--*' 49 | autojump $argv 50 | case '*' 51 | set -l output (autojump $argv) 52 | # Check for . and attempt a regular cd 53 | if [ $output = "." ] 54 | cd $argv 55 | else 56 | if test -d "$output" 57 | set_color red 58 | echo $output 59 | set_color normal 60 | cd $output 61 | else 62 | __aj_err "autojump: directory '"$argv"' not found" 63 | __aj_err "\n$output\n" 64 | __aj_err "Try `autojump --help` for more information." 65 | end 66 | end 67 | end 68 | end 69 | 70 | 71 | # jump to child directory (subdirectory of current path) 72 | function jc 73 | switch "$argv" 74 | case '-*' 75 | j $argv 76 | case '*' 77 | j (pwd) $argv 78 | end 79 | end 80 | 81 | 82 | # open autojump results in file browser 83 | function jo 84 | set -l output (autojump $argv) 85 | if test -d "$output" 86 | switch $OSTYPE 87 | case 'linux*' 88 | xdg-open (autojump $argv) 89 | case 'darwin*' 90 | open (autojump $argv) 91 | case cygwin 92 | cygstart "" (cygpath -w -a (pwd)) 93 | case '*' 94 | __aj_err "Unknown operating system: \"$OSTYPE\"" 95 | end 96 | else 97 | __aj_err "autojump: directory '"$argv"' not found" 98 | __aj_err "\n$output\n" 99 | __aj_err "Try `autojump --help` for more information." 100 | end 101 | end 102 | 103 | 104 | # open autojump results (child directory) in file browser 105 | function jco 106 | switch "$argv" 107 | case '-*' 108 | j $argv 109 | case '*' 110 | jo (pwd) $argv 111 | end 112 | end 113 | -------------------------------------------------------------------------------- /bin/autojump.lua: -------------------------------------------------------------------------------- 1 | local AUTOJUMP_DIR = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] .. "..\\AutoJump" 2 | local AUTOJUMP_BIN_DIR = AUTOJUMP_DIR .. "\\bin" 3 | local AUTOJUMP_BIN = (AUTOJUMP_BIN_DIR or clink.get_env("LOCALAPPDATA") .. "\\autojump\\bin") .. "\\autojump" 4 | 5 | function autojump_add_to_database() 6 | os.execute("python " .. "\"" .. AUTOJUMP_BIN .. "\"" .. " --add " .. "\"" .. clink.get_cwd() .. "\"" .. " 2> " .. clink.get_env("TEMP") .. "\\autojump_error.txt") 7 | end 8 | 9 | clink.prompt.register_filter(autojump_add_to_database, 99) 10 | 11 | function autojump_completion(word) 12 | for line in io.popen("python " .. "\"" .. AUTOJUMP_BIN .. "\"" .. " --complete " .. word):lines() do 13 | clink.add_match(line) 14 | end 15 | return {} 16 | end 17 | 18 | local autojump_parser = clink.arg.new_parser() 19 | autojump_parser:set_arguments({ autojump_completion }) 20 | 21 | clink.arg.register_parser("j", autojump_parser) 22 | -------------------------------------------------------------------------------- /bin/autojump.sh: -------------------------------------------------------------------------------- 1 | # the login $SHELL isn't always the one used 2 | # NOTE: problems might occur if /bin/sh is symlinked to /bin/bash 3 | if [ -n "${BASH}" ]; then 4 | shell="bash" 5 | elif [ -n "${ZSH_NAME}" ]; then 6 | shell="zsh" 7 | elif [ -n "${__fish_datadir}" ]; then 8 | shell="fish" 9 | elif [ -n "${version}" ]; then 10 | shell="tcsh" 11 | else 12 | shell=$(echo ${SHELL} | awk -F/ '{ print $NF }') 13 | fi 14 | 15 | # prevent circular loop for sh shells 16 | if [ "${shell}" = "sh" ]; then 17 | return 0 18 | 19 | # check local install 20 | elif [ -s ~/.autojump/share/autojump/autojump.${shell} ]; then 21 | source ~/.autojump/share/autojump/autojump.${shell} 22 | 23 | # check global install 24 | elif [ -s /usr/local/share/autojump/autojump.${shell} ]; then 25 | source /usr/local/share/autojump/autojump.${shell} 26 | fi 27 | -------------------------------------------------------------------------------- /bin/autojump.tcsh: -------------------------------------------------------------------------------- 1 | # set user installation paths 2 | if (-d ~/.autojump/bin) then 3 | set path = (~/.autojump/bin path) 4 | endif 5 | 6 | # prepend autojump to cwdcmd (run after every change of working directory) 7 | if (`alias cwdcmd` !~ *autojump*) then 8 | alias cwdcmd 'autojump --add $cwd >/dev/null;' `alias cwdcmd` 9 | endif 10 | 11 | #default autojump command 12 | alias j 'cd `autojump -- \!:1`' 13 | -------------------------------------------------------------------------------- /bin/autojump.zsh: -------------------------------------------------------------------------------- 1 | export AUTOJUMP_SOURCED=1 2 | 3 | # set user installation paths 4 | if [[ -d ~/.autojump/bin ]]; then 5 | path=(~/.autojump/bin ${path}) 6 | fi 7 | if [[ -d ~/.autojump/functions ]]; then 8 | fpath=(~/.autojump/functions ${fpath}) 9 | fi 10 | 11 | 12 | # set homebrew installation paths 13 | if command -v brew &>/dev/null; then 14 | local brew_prefix=${BREW_PREFIX:-$(brew --prefix)} 15 | if [[ -d "${brew_prefix}/share/zsh/site-functions" ]]; then 16 | fpath=("${brew_prefix}/share/zsh/site-functions" ${fpath}) 17 | fi 18 | fi 19 | 20 | 21 | # set error file location 22 | if [[ "$(uname)" == "Darwin" ]]; then 23 | export AUTOJUMP_ERROR_PATH=~/Library/autojump/errors.log 24 | elif [[ -n "${XDG_DATA_HOME}" ]]; then 25 | export AUTOJUMP_ERROR_PATH="${XDG_DATA_HOME}/autojump/errors.log" 26 | else 27 | export AUTOJUMP_ERROR_PATH=~/.local/share/autojump/errors.log 28 | fi 29 | 30 | if [[ ! -d ${AUTOJUMP_ERROR_PATH:h} ]]; then 31 | mkdir -p ${AUTOJUMP_ERROR_PATH:h} 32 | fi 33 | 34 | 35 | # change pwd hook 36 | autojump_chpwd() { 37 | if [[ -f "${AUTOJUMP_ERROR_PATH}" ]]; then 38 | autojump --add "$(pwd)" >/dev/null 2>>${AUTOJUMP_ERROR_PATH} &! 39 | else 40 | autojump --add "$(pwd)" >/dev/null &! 41 | fi 42 | } 43 | 44 | typeset -gaU chpwd_functions 45 | chpwd_functions+=autojump_chpwd 46 | 47 | 48 | # default autojump command 49 | j() { 50 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 51 | autojump ${@} 52 | return 53 | fi 54 | 55 | setopt localoptions noautonamedirs 56 | local output="$(autojump ${@})" 57 | if [[ -d "${output}" ]]; then 58 | if [ -t 1 ]; then # if stdout is a terminal, use colors 59 | echo -e "\\033[31m${output}\\033[0m" 60 | else 61 | echo -e "${output}" 62 | fi 63 | cd "${output}" 64 | else 65 | echo "autojump: directory '${@}' not found" 66 | echo "\n${output}\n" 67 | echo "Try \`autojump --help\` for more information." 68 | false 69 | fi 70 | } 71 | 72 | 73 | # jump to child directory (subdirectory of current path) 74 | jc() { 75 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 76 | autojump ${@} 77 | return 78 | else 79 | j $(pwd) ${@} 80 | fi 81 | } 82 | 83 | 84 | # open autojump results in file browser 85 | jo() { 86 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 87 | autojump ${@} 88 | return 89 | fi 90 | 91 | setopt localoptions noautonamedirs 92 | local output="$(autojump ${@})" 93 | if [[ -d "${output}" ]]; then 94 | case ${OSTYPE} in 95 | linux*) 96 | xdg-open "${output}" 97 | ;; 98 | darwin*) 99 | open "${output}" 100 | ;; 101 | cygwin) 102 | cygstart "" $(cygpath -w -a ${output}) 103 | ;; 104 | *) 105 | echo "Unknown operating system: ${OSTYPE}" 1>&2 106 | ;; 107 | esac 108 | else 109 | echo "autojump: directory '${@}' not found" 110 | echo "\n${output}\n" 111 | echo "Try \`autojump --help\` for more information." 112 | false 113 | fi 114 | } 115 | 116 | 117 | # open autojump results (child directory) in file browser 118 | jco() { 119 | if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then 120 | autojump ${@} 121 | return 122 | else 123 | jo $(pwd) ${@} 124 | fi 125 | } 126 | -------------------------------------------------------------------------------- /bin/autojump_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | 5 | import os 6 | import shutil 7 | import sys 8 | from codecs import open 9 | from collections import namedtuple 10 | from tempfile import NamedTemporaryFile 11 | from time import time 12 | 13 | from autojump_utils import create_dir 14 | from autojump_utils import is_osx 15 | from autojump_utils import is_python3 16 | from autojump_utils import move_file 17 | from autojump_utils import unico 18 | 19 | 20 | if sys.version_info[0] == 3: 21 | ifilter = filter 22 | imap = map 23 | else: 24 | from itertools import ifilter # noqa 25 | from itertools import imap # noqa 26 | 27 | 28 | BACKUP_THRESHOLD = 24 * 60 * 60 29 | Entry = namedtuple('Entry', ['path', 'weight']) 30 | 31 | 32 | def dictify(entries): 33 | """ 34 | Converts a list of entries into a dictionary where 35 | key = path 36 | value = weight 37 | """ 38 | result = {} 39 | for entry in entries: 40 | result[entry.path] = entry.weight 41 | return result 42 | 43 | 44 | def entriefy(data): 45 | """Converts a dictionary into an iterator of entries.""" 46 | convert = lambda tup: Entry(*tup) 47 | if is_python3(): 48 | return map(convert, data.items()) 49 | return imap(convert, data.iteritems()) 50 | 51 | 52 | def load(config): 53 | """Returns a dictonary (key=path, value=weight) loaded from data file.""" 54 | xdg_aj_home = os.path.join( 55 | os.path.expanduser('~'), 56 | '.local', 57 | 'share', 58 | 'autojump', 59 | ) 60 | 61 | if is_osx() and os.path.exists(xdg_aj_home): 62 | migrate_osx_xdg_data(config) 63 | 64 | if not os.path.exists(config['data_path']): 65 | return {} 66 | 67 | # example: u'10.0\t/home/user\n' -> ['10.0', u'/home/user'] 68 | parse = lambda line: line.strip().split('\t') 69 | 70 | correct_length = lambda x: len(x) == 2 71 | 72 | # example: ['10.0', u'/home/user'] -> (u'/home/user', 10.0) 73 | tupleize = lambda x: (x[1], float(x[0])) 74 | 75 | try: 76 | with open( 77 | config['data_path'], 78 | 'r', encoding='utf-8', 79 | errors='replace', 80 | ) as f: 81 | return dict( 82 | imap( 83 | tupleize, 84 | ifilter(correct_length, imap(parse, f)), 85 | ), 86 | ) 87 | except (IOError, EOFError): 88 | return load_backup(config) 89 | 90 | 91 | def load_backup(config): 92 | if os.path.exists(config['backup_path']): 93 | move_file(config['backup_path'], config['data_path']) 94 | return load(config) 95 | return {} 96 | 97 | 98 | def migrate_osx_xdg_data(config): 99 | """ 100 | Older versions incorrectly used Linux XDG_DATA_HOME paths on OS X. This 101 | migrates autojump files from ~/.local/share/autojump to ~/Library/autojump 102 | """ 103 | assert is_osx(), 'This function should only be run on OS X.' 104 | 105 | xdg_data_home = os.path.join(os.path.expanduser('~'), '.local', 'share') 106 | xdg_aj_home = os.path.join(xdg_data_home, 'autojump') 107 | data_path = os.path.join(xdg_aj_home, 'autojump.txt') 108 | backup_path = os.path.join(xdg_aj_home, 'autojump.txt.bak') 109 | 110 | if os.path.exists(data_path): 111 | move_file(data_path, config['data_path']) 112 | if os.path.exists(backup_path): 113 | move_file(backup_path, config['backup_path']) 114 | 115 | # cleanup 116 | shutil.rmtree(xdg_aj_home) 117 | if len(os.listdir(xdg_data_home)) == 0: 118 | shutil.rmtree(xdg_data_home) 119 | 120 | 121 | def save(config, data): 122 | """Save data and create backup, creating a new data file if necessary.""" 123 | data_dir = os.path.dirname(config['data_path']) 124 | create_dir(data_dir) 125 | 126 | # atomically save by writing to temporary file and moving to destination 127 | try: 128 | temp = NamedTemporaryFile(delete=False, dir=data_dir) 129 | # Windows cannot reuse the same open file name 130 | temp.close() 131 | 132 | with open(temp.name, 'w', encoding='utf-8', errors='replace') as f: 133 | for path, weight in data.items(): 134 | f.write(unico('%s\t%s\n' % (weight, path))) 135 | 136 | f.flush() 137 | os.fsync(f) 138 | except IOError as ex: 139 | print('Error saving autojump data (disk full?)' % ex, file=sys.stderr) 140 | sys.exit(1) 141 | 142 | # move temp_file -> autojump.txt 143 | move_file(temp.name, config['data_path']) 144 | 145 | # create backup file if it doesn't exist or is older than BACKUP_THRESHOLD 146 | if not os.path.exists(config['backup_path']) or \ 147 | (time() - os.path.getmtime(config['backup_path']) > BACKUP_THRESHOLD): # noqa 148 | shutil.copy(config['data_path'], config['backup_path']) 149 | -------------------------------------------------------------------------------- /bin/autojump_match.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | import os 4 | import re 5 | from difflib import SequenceMatcher 6 | 7 | from autojump_utils import is_python3 8 | from autojump_utils import last 9 | 10 | 11 | if is_python3(): # pragma: no cover 12 | ifilter = filter 13 | imap = map 14 | os.getcwdu = os.getcwd 15 | else: 16 | from itertools import ifilter 17 | from itertools import imap 18 | 19 | 20 | def match_anywhere(needles, haystack, ignore_case=False): 21 | """ 22 | Matches needles anywhere in the path as long as they're in the same (but 23 | not necessary consecutive) order. 24 | 25 | For example: 26 | needles = ['foo', 'baz'] 27 | regex needle = r'.*foo.*baz.*' 28 | haystack = [ 29 | (path='/foo/bar/baz', weight=10), 30 | (path='/baz/foo/bar', weight=10), 31 | (path='/foo/baz', weight=10), 32 | ] 33 | 34 | result = [ 35 | (path='/moo/foo/baz', weight=10), 36 | (path='/foo/baz', weight=10), 37 | ] 38 | """ 39 | regex_needle = '.*' + '.*'.join(imap(re.escape, needles)) + '.*' 40 | regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE 41 | found = lambda haystack: re.search( 42 | regex_needle, 43 | haystack.path, 44 | flags=regex_flags, 45 | ) 46 | return ifilter(found, haystack) 47 | 48 | 49 | def match_consecutive(needles, haystack, ignore_case=False): 50 | """ 51 | Matches consecutive needles at the end of a path. 52 | 53 | For example: 54 | needles = ['foo', 'baz'] 55 | haystack = [ 56 | (path='/foo/bar/baz', weight=10), 57 | (path='/foo/baz/moo', weight=10), 58 | (path='/moo/foo/baz', weight=10), 59 | (path='/foo/baz', weight=10), 60 | ] 61 | 62 | # We can't actually use re.compile because of re.UNICODE 63 | regex_needle = re.compile(r''' 64 | foo # needle #1 65 | [^/]* # all characters except os.sep zero or more times 66 | / # os.sep 67 | [^/]* # all characters except os.sep zero or more times 68 | baz # needle #2 69 | [^/]* # all characters except os.sep zero or more times 70 | $ # end of string 71 | ''') 72 | 73 | result = [ 74 | (path='/moo/foo/baz', weight=10), 75 | (path='/foo/baz', weight=10), 76 | ] 77 | """ 78 | regex_no_sep = '[^' + os.sep + ']*' 79 | regex_no_sep_end = regex_no_sep + '$' 80 | regex_one_sep = regex_no_sep + os.sep + regex_no_sep 81 | regex_needle = regex_one_sep.join(imap(re.escape, needles)) + regex_no_sep_end 82 | regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE 83 | found = lambda entry: re.search( 84 | regex_needle, 85 | entry.path, 86 | flags=regex_flags, 87 | ) 88 | return ifilter(found, haystack) 89 | 90 | 91 | def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6): 92 | """ 93 | Performs an approximate match with the last needle against the end of 94 | every path past an acceptable threshold. 95 | 96 | For example: 97 | needles = ['foo', 'bar'] 98 | haystack = [ 99 | (path='/foo/bar/baz', weight=11), 100 | (path='/foo/baz/moo', weight=10), 101 | (path='/moo/foo/baz', weight=10), 102 | (path='/foo/baz', weight=10), 103 | (path='/foo/bar', weight=10), 104 | ] 105 | 106 | result = [ 107 | (path='/foo/bar/baz', weight=11), 108 | (path='/moo/foo/baz', weight=10), 109 | (path='/foo/baz', weight=10), 110 | (path='/foo/bar', weight=10), 111 | ] 112 | 113 | This is a weak heuristic and used as a last resort to find matches. 114 | """ 115 | end_dir = lambda path: last(os.path.split(path)) 116 | if ignore_case: 117 | needle = last(needles).lower() 118 | match_percent = lambda entry: SequenceMatcher( 119 | a=needle, 120 | b=end_dir(entry.path.lower()), 121 | ).ratio() 122 | else: 123 | needle = last(needles) 124 | match_percent = lambda entry: SequenceMatcher( 125 | a=needle, 126 | b=end_dir(entry.path), 127 | ).ratio() 128 | meets_threshold = lambda entry: match_percent(entry) >= threshold 129 | return ifilter(meets_threshold, haystack) 130 | -------------------------------------------------------------------------------- /bin/autojump_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | 5 | import errno 6 | import os 7 | import platform 8 | import re 9 | import shutil 10 | import sys 11 | import unicodedata 12 | from itertools import islice 13 | 14 | if sys.version_info[0] == 3: 15 | imap = map 16 | os.getcwdu = os.getcwd 17 | else: 18 | from itertools import imap 19 | 20 | 21 | def create_dir(path): 22 | """Creates a directory atomically.""" 23 | try: 24 | os.makedirs(path) 25 | except OSError as exception: 26 | if exception.errno != errno.EEXIST: 27 | raise 28 | 29 | 30 | def encode_local(string): 31 | """Converts string into user's preferred encoding.""" 32 | if is_python3(): 33 | return string 34 | return string.encode(sys.getfilesystemencoding() or 'utf-8') 35 | 36 | 37 | def first(xs): 38 | it = iter(xs) 39 | try: 40 | if is_python3(): 41 | return it.__next__() 42 | return it.next() 43 | except StopIteration: 44 | return None 45 | 46 | 47 | def get_tab_entry_info(entry, separator): 48 | """ 49 | Given a tab entry in the following format return needle, index, and path: 50 | 51 | [needle]__[index]__[path] 52 | """ 53 | needle, index, path = None, None, None 54 | 55 | match_needle = re.search(r'(.*?)' + separator, entry) 56 | match_index = re.search(separator + r'([0-9]{1})', entry) 57 | match_path = re.search( 58 | separator + r'[0-9]{1}' + separator + r'(.*)', 59 | entry, 60 | ) 61 | 62 | if match_needle: 63 | needle = match_needle.group(1) 64 | 65 | if match_index: 66 | index = int(match_index.group(1)) 67 | 68 | if match_path: 69 | path = match_path.group(1) 70 | 71 | return needle, index, path 72 | 73 | 74 | def get_pwd(): 75 | try: 76 | return os.getcwdu() 77 | except OSError: 78 | print('Current directory no longer exists.', file=sys.stderr) 79 | raise 80 | 81 | 82 | def has_uppercase(string): 83 | if is_python3(): 84 | return any(ch.isupper() for ch in string) 85 | return any(unicodedata.category(c) == 'Lu' for c in unicode(string)) 86 | 87 | 88 | def in_bash(): 89 | return 'bash' in os.getenv('SHELL') 90 | 91 | 92 | def is_autojump_sourced(): 93 | return '1' == os.getenv('AUTOJUMP_SOURCED') 94 | 95 | 96 | def is_python2(): 97 | return sys.version_info[0] == 2 98 | 99 | 100 | def is_python3(): 101 | return sys.version_info[0] == 3 102 | 103 | 104 | def is_linux(): 105 | return platform.system() == 'Linux' 106 | 107 | 108 | def is_osx(): 109 | return platform.system() == 'Darwin' 110 | 111 | 112 | def is_windows(): 113 | return platform.system() == 'Windows' 114 | 115 | 116 | def last(xs): 117 | it = iter(xs) 118 | tmp = None 119 | try: 120 | if is_python3(): 121 | while True: 122 | tmp = it.__next__() 123 | else: 124 | while True: 125 | tmp = it.next() 126 | except StopIteration: 127 | return tmp 128 | 129 | 130 | def move_file(src, dst): 131 | """ 132 | Atomically move file. 133 | 134 | Windows does not allow for atomic file renaming (which is used by 135 | os.rename / shutil.move) so destination paths must first be deleted. 136 | """ 137 | if is_windows() and os.path.exists(dst): 138 | # raises exception if file is in use on Windows 139 | os.remove(dst) 140 | shutil.move(src, dst) 141 | 142 | 143 | def print_entry(entry): 144 | print_local('%.1f:\t%s' % (entry.weight, entry.path)) 145 | 146 | 147 | def print_local(string): 148 | print(encode_local(string)) 149 | 150 | 151 | def print_tab_menu(needle, tab_entries, separator): 152 | """ 153 | Prints the tab completion menu according to the following format: 154 | 155 | [needle]__[index]__[possible_match] 156 | 157 | The needle (search pattern) and index are necessary to recreate the results 158 | on subsequent calls. 159 | """ 160 | for i, entry in enumerate(tab_entries): 161 | print_local( 162 | '%s%s%d%s%s' % ( 163 | needle, 164 | separator, 165 | i + 1, 166 | separator, 167 | entry.path, 168 | ), 169 | ) 170 | 171 | 172 | def sanitize(directories): 173 | # edge case to allow '/' as a valid path 174 | clean = lambda x: unico(x) if x == os.sep else unico(x).rstrip(os.sep) 175 | return list(imap(clean, directories)) 176 | 177 | 178 | def second(xs): 179 | it = iter(xs) 180 | try: 181 | if is_python2(): 182 | it.next() 183 | return it.next() 184 | elif is_python3(): 185 | next(it) 186 | return next(it) 187 | except StopIteration: 188 | return None 189 | 190 | 191 | def surround_quotes(string): 192 | """ 193 | Bash has problems dealing with certain paths so we're surrounding all 194 | path outputs with quotes. 195 | """ 196 | if in_bash() and string: 197 | # Python 2.6 requres field numbers 198 | return '"{0}"'.format(string) 199 | return string 200 | 201 | 202 | def take(n, iterable): 203 | """Return first n items of an iterable.""" 204 | return islice(iterable, n) 205 | 206 | 207 | def unico(string): 208 | """Converts into Unicode string.""" 209 | if is_python2() and not isinstance(string, unicode): 210 | return unicode(string, encoding='utf-8', errors='replace') 211 | return string 212 | -------------------------------------------------------------------------------- /bin/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wting/autojump/ee21082751da739c65fe0ec2d02ca95d4266aebc/bin/icon.png -------------------------------------------------------------------------------- /bin/j.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | echo %*|>nul findstr /rx \-.* 5 | if ERRORLEVEL 1 ( 6 | for /f "delims=" %%i in ('python "%~dp0\autojump" %*') do set new_path=%%i 7 | if exist !new_path!\nul ( 8 | echo !new_path! 9 | pushd !new_path! 10 | REM endlocal is necessary so that we can change directory for outside of this script 11 | REM but will automatically popd. We mush pushd twice to work around this. 12 | pushd !new_path! 13 | endlocal 14 | popd 15 | ) else ( 16 | echo autojump: directory %* not found 17 | echo try `autojump --help` for more information 18 | ) 19 | ) else ( 20 | python "%~dp0\autojump" %* 21 | ) 22 | -------------------------------------------------------------------------------- /bin/jc.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo %*|>nul findstr /rx \-.* 4 | if ERRORLEVEL 1 ( 5 | "%~dp0\j.bat" "%cd%" %* 6 | ) else ( 7 | python "%~dp0\autojump" %* 8 | ) 9 | -------------------------------------------------------------------------------- /bin/jco.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo %*|>nul findstr /rx \-.* 4 | if ERRORLEVEL 1 ( 5 | "%~dp0\jc.bat" "%cd%" %* 6 | ) else ( 7 | python "%~dp0\autojump" %* 8 | ) 9 | -------------------------------------------------------------------------------- /bin/jo.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | echo %*|>nul findstr /rx \-.* 5 | if ERRORLEVEL 1 ( 6 | for /f "delims=" %%i in ('python "%~dp0\autojump" %*') do set new_path=%%i 7 | if exist !new_path!\nul ( 8 | start "" "explorer" !new_path! 9 | ) else ( 10 | echo autojump: directory %* not found 11 | echo try `autojump --help` for more information 12 | ) 13 | ) else ( 14 | python "%~dp0\autojump" %* 15 | ) 16 | -------------------------------------------------------------------------------- /docs/autojump.1: -------------------------------------------------------------------------------- 1 | .\" Automatically generated by Pandoc 1.16.0.2 2 | .\" 3 | .TH "autojump" "1" "2018\-09\-09" "release\-v22.5.3" "" 4 | .hy 5 | .SS NAME 6 | .PP 7 | autojump \- a faster way to navigate your filesystem 8 | .SS DESCRIPTION 9 | .PP 10 | autojump is a faster way to navigate your filesystem. 11 | It works by maintaining a database of the directories you use the most 12 | from the command line. 13 | .PP 14 | \f[I]Directories must be visited first before they can be jumped to.\f[] 15 | .SS USAGE 16 | .PP 17 | \f[C]j\f[] is a convenience wrapper function around \f[C]autojump\f[]. 18 | Any option that can be used with \f[C]autojump\f[] can be used with 19 | \f[C]j\f[] and vice versa. 20 | .IP \[bu] 2 21 | Jump To A Directory That Contains \f[C]foo\f[]: 22 | .RS 2 23 | .IP 24 | .nf 25 | \f[C] 26 | j\ foo 27 | \f[] 28 | .fi 29 | .RE 30 | .IP \[bu] 2 31 | Jump To A Child Directory: 32 | .RS 2 33 | .PP 34 | Sometimes it\[aq]s convenient to jump to a child directory 35 | (sub\-directory of current directory) rather than typing out the full 36 | name. 37 | .IP 38 | .nf 39 | \f[C] 40 | jc\ bar 41 | \f[] 42 | .fi 43 | .RE 44 | .IP \[bu] 2 45 | Open File Manager To Directories (instead of jumping): 46 | .RS 2 47 | .PP 48 | Instead of jumping to a directory, you can open a file explorer window 49 | (Mac Finder, Windows Explorer, GNOME Nautilus, etc.) to the directory 50 | instead. 51 | .IP 52 | .nf 53 | \f[C] 54 | jo\ music 55 | \f[] 56 | .fi 57 | .PP 58 | Opening a file manager to a child directory is also supported: 59 | .IP 60 | .nf 61 | \f[C] 62 | jco\ images 63 | \f[] 64 | .fi 65 | .RE 66 | .IP \[bu] 2 67 | Using Multiple Arguments: 68 | .RS 2 69 | .PP 70 | Let\[aq]s assume the following database: 71 | .IP 72 | .nf 73 | \f[C] 74 | 30\ \ \ /home/user/mail/inbox 75 | 10\ \ \ /home/user/work/inbox 76 | \f[] 77 | .fi 78 | .PP 79 | \f[C]j\ in\f[] would jump into /home/user/mail/inbox as the higher 80 | weighted entry. 81 | However you can pass multiple arguments to autojump to prefer a 82 | different entry. 83 | In the above example, \f[C]j\ w\ in\f[] would then change directory to 84 | /home/user/work/inbox. 85 | .RE 86 | .PP 87 | For more options refer to help: 88 | .IP 89 | .nf 90 | \f[C] 91 | autojump\ \-\-help 92 | \f[] 93 | .fi 94 | .SS KNOWN ISSUES 95 | .IP \[bu] 2 96 | autojump does not support directories that begin with \f[C]\-\f[]. 97 | .IP \[bu] 2 98 | For bash users, autojump keeps track of directories by modifying 99 | \f[C]$PROMPT_COMMAND\f[]. 100 | Do not overwrite \f[C]$PROMPT_COMMAND\f[]: 101 | .RS 2 102 | .IP 103 | .nf 104 | \f[C] 105 | export\ PROMPT_COMMAND="history\ \-a" 106 | \f[] 107 | .fi 108 | .PP 109 | Instead append to the end of the existing $PROMPT_COMMAND: 110 | .IP 111 | .nf 112 | \f[C] 113 | export\ PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND\ ;}\ history\ \-a" 114 | \f[] 115 | .fi 116 | .RE 117 | .SS REPORTING BUGS 118 | .PP 119 | For any questions or issues please visit: 120 | .IP 121 | .nf 122 | \f[C] 123 | https://github.com/wting/autojump/issues 124 | \f[] 125 | .fi 126 | .SS AUTHORS 127 | .PP 128 | autojump was originally written by Joël Schaerer, and currently 129 | maintained by William Ting. 130 | More contributors can be found in \f[C]AUTHORS\f[]. 131 | .SS COPYRIGHT 132 | .PP 133 | Copyright © 2016 Free Software Foundation, Inc. 134 | License GPLv3+: GNU GPL version 3 or later 135 | . 136 | This is free software: you are free to change and redistribute it. 137 | There is NO WARRANTY, to the extent permitted by law. 138 | -------------------------------------------------------------------------------- /docs/body.md: -------------------------------------------------------------------------------- 1 | KNOWN ISSUES 2 | ------------ 3 | 4 | - autojump does not support directories that begin with `-`. 5 | 6 | - For bash users, autojump keeps track of directories by modifying 7 | `$PROMPT_COMMAND`. Do not overwrite `$PROMPT_COMMAND`: 8 | 9 | export PROMPT_COMMAND="history -a" 10 | 11 | Instead append to the end of the existing \$PROMPT\_COMMAND: 12 | 13 | export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ;} history -a" 14 | 15 | REPORTING BUGS 16 | -------------- 17 | 18 | For any questions or issues please visit: 19 | 20 | https://github.com/wting/autojump/issues 21 | 22 | AUTHORS 23 | ------- 24 | 25 | autojump was originally written by Joël Schaerer, and currently maintained by 26 | William Ting. More contributors can be found in `AUTHORS`. 27 | 28 | COPYRIGHT 29 | --------- 30 | 31 | Copyright © 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 32 | 3 or later . This is free software: you are 33 | free to change and redistribute it. There is NO WARRANTY, to the extent 34 | permitted by law. 35 | -------------------------------------------------------------------------------- /docs/header.md: -------------------------------------------------------------------------------- 1 | NAME 2 | ---- 3 | 4 | autojump - a faster way to navigate your filesystem 5 | 6 | DESCRIPTION 7 | ----------- 8 | 9 | autojump is a faster way to navigate your filesystem. It works by maintaining a 10 | database of the directories you use the most from the command line. 11 | 12 | *Directories must be visited first before they can be jumped to.* 13 | 14 | USAGE 15 | ----- 16 | 17 | `j` is a convenience wrapper function around `autojump`. Any option that can 18 | be used with `autojump` can be used with `j` and vice versa. 19 | 20 | - Jump To A Directory That Contains `foo`: 21 | 22 | j foo 23 | 24 | - Jump To A Child Directory: 25 | 26 | Sometimes it's convenient to jump to a child directory (sub-directory of 27 | current directory) rather than typing out the full name. 28 | 29 | jc bar 30 | 31 | - Open File Manager To Directories (instead of jumping): 32 | 33 | Instead of jumping to a directory, you can open a file explorer window (Mac 34 | Finder, Windows Explorer, GNOME Nautilus, etc.) to the directory instead. 35 | 36 | jo music 37 | 38 | Opening a file manager to a child directory is also supported: 39 | 40 | jco images 41 | 42 | - Using Multiple Arguments: 43 | 44 | Let's assume the following database: 45 | 46 | 30 /home/user/mail/inbox 47 | 10 /home/user/work/inbox 48 | 49 | `j in` would jump into /home/user/mail/inbox as the higher weighted 50 | entry. However you can pass multiple arguments to autojump to prefer 51 | a different entry. In the above example, `j w in` would then change 52 | directory to /home/user/work/inbox. 53 | 54 | For more options refer to help: 55 | 56 | autojump --help 57 | -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | ## INSTALLATION 2 | 3 | ### REQUIREMENTS 4 | 5 | - Python v2.6+ or Python v3.3+ 6 | - Supported shells 7 | - bash - first class support 8 | - zsh - first class support 9 | - fish - community supported 10 | - tcsh - community supported 11 | - clink - community supported 12 | - Supported platforms 13 | - Linux - first class support 14 | - OS X - first class support 15 | - Windows - community supported 16 | - BSD - community supported 17 | - Supported installation methods 18 | - source code - first class support 19 | - Debian and derivatives - first class support 20 | - ArchLinux / Gentoo / openSUSE / RedHat and derivatives - community supported 21 | - Homebrew / MacPorts - community supported 22 | 23 | Due to limited time and resources, only "first class support" items will be 24 | maintained by the primary committers. All "community supported" items will be 25 | updated based on pull requests submitted by the general public. 26 | 27 | Please continue opening issues and providing feedback for community supported 28 | items since consolidating information helps other users troubleshoot and submit 29 | enhancements and fixes. 30 | 31 | ### MANUAL 32 | 33 | Grab a copy of autojump: 34 | 35 | git clone git://github.com/wting/autojump.git 36 | 37 | Run the installation script and follow on screen instructions. 38 | 39 | cd autojump 40 | ./install.py or ./uninstall.py 41 | 42 | ### AUTOMATIC 43 | 44 | #### Linux 45 | 46 | autojump is included in the following distro repositories, please use relevant 47 | package management utilities to install (e.g. apt-get, yum, pacman, etc): 48 | 49 | - Debian, Ubuntu, Linux Mint 50 | 51 | All Debian-derived distros require manual activation for policy reasons, 52 | please see `/usr/share/doc/autojump/README.Debian`. 53 | 54 | - RedHat, Fedora, CentOS 55 | 56 | Install `autojump-zsh` for zsh, `autojump-fish` for fish, etc. 57 | 58 | - ArchLinux 59 | - Gentoo 60 | - Frugalware 61 | - Slackware 62 | 63 | #### OS X 64 | 65 | Homebrew is the recommended installation method for Mac OS X: 66 | 67 | brew install autojump 68 | 69 | MacPorts is also available: 70 | 71 | port install autojump 72 | 73 | ## Windows 74 | 75 | Windows support is enabled by [clink](https://mridgers.github.io/clink/) which 76 | should be installed prior to installing autojump. 77 | -------------------------------------------------------------------------------- /docs/manpage_header.md: -------------------------------------------------------------------------------- 1 | % autojump(1) release-v22.5.3 2 | % 3 | % 2018-09-09 4 | -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | 5 | import os 6 | import platform 7 | import shutil 8 | import sys 9 | 10 | sys.path.append('bin') 11 | from autojump_argparse import ArgumentParser # noqa 12 | 13 | SUPPORTED_SHELLS = ('bash', 'zsh', 'fish', 'tcsh') 14 | 15 | 16 | def cp(src, dest, dryrun=False): 17 | print('copying file: %s -> %s' % (src, dest)) 18 | if not dryrun: 19 | shutil.copy(src, dest) 20 | 21 | 22 | def get_shell(): 23 | return os.path.basename(os.getenv('SHELL', '')) 24 | 25 | 26 | def mkdir(path, dryrun=False): 27 | print('creating directory:', path) 28 | if not dryrun and not os.path.exists(path): 29 | os.makedirs(path) 30 | 31 | 32 | def modify_autojump_sh(etc_dir, share_dir, dryrun=False): 33 | """Append custom installation path to autojump.sh""" 34 | custom_install = '\ 35 | \n# check custom install \ 36 | \nif [ -s %s/autojump.${shell} ]; then \ 37 | \n source %s/autojump.${shell} \ 38 | \nfi\n' % (share_dir, share_dir) 39 | 40 | with open(os.path.join(etc_dir, 'autojump.sh'), 'a') as f: 41 | f.write(custom_install) 42 | 43 | 44 | def modify_autojump_lua(clink_dir, bin_dir, dryrun=False): 45 | """Prepend custom AUTOJUMP_BIN_DIR definition to autojump.lua""" 46 | custom_install = "local AUTOJUMP_BIN_DIR = \"%s\"\n" % bin_dir.replace( 47 | '\\', 48 | '\\\\', 49 | ) 50 | clink_file = os.path.join(clink_dir, 'autojump.lua') 51 | with open(clink_file, 'r') as f: 52 | original = f.read() 53 | with open(clink_file, 'w') as f: 54 | f.write(custom_install + original) 55 | 56 | 57 | def parse_arguments(): # noqa 58 | if platform.system() == 'Windows': 59 | default_user_destdir = os.path.join( 60 | os.getenv('LOCALAPPDATA', ''), 61 | 'autojump', 62 | ) 63 | else: 64 | default_user_destdir = os.path.join( 65 | os.path.expanduser('~'), 66 | '.autojump', 67 | ) 68 | default_user_prefix = '' 69 | default_user_zshshare = 'functions' 70 | default_system_destdir = '/' 71 | default_system_prefix = '/usr/local' 72 | default_system_zshshare = '/usr/share/zsh/site-functions' 73 | default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink') 74 | 75 | parser = ArgumentParser( 76 | description='Installs autojump globally for root users, otherwise \ 77 | installs in current user\'s home directory.' 78 | ) 79 | parser.add_argument( 80 | '-n', '--dryrun', action='store_true', default=False, 81 | help='simulate installation', 82 | ) 83 | parser.add_argument( 84 | '-f', '--force', action='store_true', default=False, 85 | help='skip root user, shell type, Python version checks', 86 | ) 87 | parser.add_argument( 88 | '-d', '--destdir', metavar='DIR', default=default_user_destdir, 89 | help='set destination to DIR', 90 | ) 91 | parser.add_argument( 92 | '-p', '--prefix', metavar='DIR', default=default_user_prefix, 93 | help='set prefix to DIR', 94 | ) 95 | parser.add_argument( 96 | '-z', '--zshshare', metavar='DIR', default=default_user_zshshare, 97 | help='set zsh share destination to DIR', 98 | ) 99 | parser.add_argument( 100 | '-c', '--clinkdir', metavar='DIR', default=default_clink_dir, 101 | help='set clink directory location to DIR (Windows only)', 102 | ) 103 | parser.add_argument( 104 | '-s', '--system', action='store_true', default=False, 105 | help='install system wide for all users', 106 | ) 107 | 108 | args = parser.parse_args() 109 | 110 | if not args.force: 111 | if sys.version_info[0] == 2 and sys.version_info[1] < 6: 112 | print('Python v2.6+ or v3.0+ required.', file=sys.stderr) 113 | sys.exit(1) 114 | if args.system: 115 | if platform.system() == 'Windows': 116 | print( 117 | 'System-wide installation is not supported on Windows.', 118 | file=sys.stderr, 119 | ) 120 | sys.exit(1) 121 | elif os.geteuid() != 0: 122 | print( 123 | 'Please rerun as root for system-wide installation.', 124 | file=sys.stderr, 125 | ) 126 | sys.exit(1) 127 | 128 | if platform.system() != 'Windows' \ 129 | and get_shell() not in SUPPORTED_SHELLS: 130 | print( 131 | 'Unsupported shell: %s' % os.getenv('SHELL'), 132 | file=sys.stderr, 133 | ) 134 | sys.exit(1) 135 | 136 | if args.destdir != default_user_destdir \ 137 | or args.prefix != default_user_prefix \ 138 | or args.zshshare != default_user_zshshare: 139 | args.custom_install = True 140 | else: 141 | args.custom_install = False 142 | 143 | if args.system: 144 | if args.custom_install: 145 | print( 146 | 'Custom paths incompatible with --system option.', 147 | file=sys.stderr, 148 | ) 149 | sys.exit(1) 150 | 151 | args.destdir = default_system_destdir 152 | args.prefix = default_system_prefix 153 | args.zshshare = default_system_zshshare 154 | 155 | return args 156 | 157 | 158 | def show_post_installation_message(etc_dir, share_dir, bin_dir): 159 | if platform.system() == 'Windows': 160 | print('\nPlease manually add %s to your user path' % bin_dir) 161 | else: 162 | if get_shell() == 'fish': 163 | aj_shell = '%s/autojump.fish' % share_dir 164 | source_msg = 'if test -f %s; . %s; end' % (aj_shell, aj_shell) 165 | rcfile = '~/.config/fish/config.fish' 166 | else: 167 | aj_shell = '%s/autojump.sh' % etc_dir 168 | source_msg = '[[ -s %s ]] && source %s' % (aj_shell, aj_shell) 169 | 170 | if platform.system() == 'Darwin' and get_shell() == 'bash': 171 | rcfile = '~/.profile' 172 | else: 173 | rcfile = '~/.%src' % get_shell() 174 | 175 | print('\nPlease manually add the following line(s) to %s:' % rcfile) 176 | print('\n\t' + source_msg) 177 | if get_shell() == 'zsh': 178 | print('\n\tautoload -U compinit && compinit -u') 179 | 180 | print('\nPlease restart terminal(s) before running autojump.\n') 181 | 182 | 183 | def main(args): 184 | if args.dryrun: 185 | print('Installing autojump to %s (DRYRUN)...' % args.destdir) 186 | else: 187 | print('Installing autojump to %s ...' % args.destdir) 188 | 189 | bin_dir = os.path.join(args.destdir, args.prefix, 'bin') 190 | etc_dir = os.path.join(args.destdir, 'etc', 'profile.d') 191 | doc_dir = os.path.join(args.destdir, args.prefix, 'share', 'man', 'man1') 192 | share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump') 193 | zshshare_dir = os.path.join(args.destdir, args.zshshare) 194 | 195 | mkdir(bin_dir, args.dryrun) 196 | mkdir(doc_dir, args.dryrun) 197 | mkdir(etc_dir, args.dryrun) 198 | mkdir(share_dir, args.dryrun) 199 | 200 | cp('./bin/autojump', bin_dir, args.dryrun) 201 | cp('./bin/autojump_argparse.py', bin_dir, args.dryrun) 202 | cp('./bin/autojump_data.py', bin_dir, args.dryrun) 203 | cp('./bin/autojump_match.py', bin_dir, args.dryrun) 204 | cp('./bin/autojump_utils.py', bin_dir, args.dryrun) 205 | cp('./bin/icon.png', share_dir, args.dryrun) 206 | cp('./docs/autojump.1', doc_dir, args.dryrun) 207 | 208 | if platform.system() == 'Windows': 209 | cp('./bin/autojump.lua', args.clinkdir, args.dryrun) 210 | cp('./bin/autojump.bat', bin_dir, args.dryrun) 211 | cp('./bin/j.bat', bin_dir, args.dryrun) 212 | cp('./bin/jc.bat', bin_dir, args.dryrun) 213 | cp('./bin/jo.bat', bin_dir, args.dryrun) 214 | cp('./bin/jco.bat', bin_dir, args.dryrun) 215 | 216 | if args.custom_install: 217 | modify_autojump_lua(args.clinkdir, bin_dir, args.dryrun) 218 | else: 219 | mkdir(etc_dir, args.dryrun) 220 | mkdir(share_dir, args.dryrun) 221 | mkdir(zshshare_dir, args.dryrun) 222 | 223 | cp('./bin/autojump.sh', etc_dir, args.dryrun) 224 | cp('./bin/autojump.bash', share_dir, args.dryrun) 225 | cp('./bin/autojump.fish', share_dir, args.dryrun) 226 | cp('./bin/autojump.zsh', share_dir, args.dryrun) 227 | cp('./bin/_j', zshshare_dir, args.dryrun) 228 | 229 | if args.custom_install: 230 | modify_autojump_sh(etc_dir, share_dir, args.dryrun) 231 | 232 | show_post_installation_message(etc_dir, share_dir, bin_dir) 233 | 234 | 235 | if __name__ == '__main__': 236 | sys.exit(main(parse_arguments())) 237 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wting/autojump/ee21082751da739c65fe0ec2d02ca95d4266aebc/tests/__init__.py -------------------------------------------------------------------------------- /tests/integration/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wting/autojump/ee21082751da739c65fe0ec2d02ca95d4266aebc/tests/integration/__init__.py -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wting/autojump/ee21082751da739c65fe0ec2d02ca95d4266aebc/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/autojump_match_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | import sys 5 | 6 | import pytest 7 | 8 | sys.path.append(os.path.join(os.getcwd(), 'bin')) # noqa 9 | from autojump_data import Entry 10 | from autojump_match import match_anywhere 11 | from autojump_match import match_consecutive 12 | 13 | 14 | class TestMatchAnywhere(object): 15 | 16 | entry1 = Entry('/foo/bar/baz', 10) 17 | entry2 = Entry('/baz/foo/bar', 10) 18 | entry3 = Entry('/foo/baz', 10) 19 | entry4 = Entry('/中/zhong/国/guo', 10) 20 | entry5 = Entry('/is\'t/this/a/b*tchin/edge/case?', 10) 21 | win_entry1 = Entry('C:\\foo\\bar\\baz', 10) 22 | win_entry2 = Entry('D:\Program Files (x86)\GIMP', 10) 23 | win_entry3 = Entry('C:\Windows\System32', 10) 24 | 25 | @pytest.fixture 26 | def haystack(self): 27 | return [ 28 | self.entry1, 29 | self.entry2, 30 | self.entry3, 31 | self.entry4, 32 | self.entry5, 33 | ] 34 | 35 | @pytest.fixture 36 | def windows_haystack(self): 37 | return [self.win_entry1, self.win_entry2, self.win_entry3] 38 | 39 | def test_single_needle(self, haystack): 40 | assert list(match_anywhere(['bar'], haystack)) == [self.entry1, self.entry2] 41 | 42 | def test_consecutive(self, haystack): 43 | assert list(match_anywhere(['foo', 'bar'], haystack)) \ 44 | == [self.entry1, self.entry2] 45 | assert list(match_anywhere(['bar', 'foo'], haystack)) == [] 46 | 47 | def test_skip(self, haystack): 48 | assert list(match_anywhere(['baz', 'bar'], haystack)) == [self.entry2] 49 | assert list(match_anywhere(['中', '国'], haystack)) == [self.entry4] 50 | 51 | def test_ignore_case(self, haystack): 52 | assert list(match_anywhere(['bAz', 'bAR'], haystack, ignore_case=True)) \ 53 | == [self.entry2] 54 | 55 | def test_backslashes_for_windows_paths(self, windows_haystack): 56 | # https://github.com/wting/autojump/issues/281 57 | assert list(match_anywhere(['foo', 'baz'], windows_haystack)) \ 58 | == [self.win_entry1] 59 | assert list(match_anywhere(['program', 'gimp'], windows_haystack, True)) \ 60 | == [self.win_entry2] 61 | assert list(match_anywhere(['win', '32'], windows_haystack, True)) \ 62 | == [self.win_entry3] 63 | 64 | def test_wildcard_in_needle(self, haystack): 65 | # https://github.com/wting/autojump/issues/402 66 | assert list(match_anywhere(['*', 'this'], haystack)) == [] 67 | assert list(match_anywhere(['this', '*'], haystack)) == [self.entry5] 68 | 69 | 70 | class TestMatchConsecutive(object): 71 | 72 | entry1 = Entry('/foo/bar/baz', 10) 73 | entry2 = Entry('/baz/foo/bar', 10) 74 | entry3 = Entry('/foo/baz', 10) 75 | entry4 = Entry('/中/zhong/国/guo', 10) 76 | entry5 = Entry('/日/本', 10) 77 | entry6 = Entry('/is\'t/this/a/b*tchin/edge/case?', 10) 78 | win_entry1 = Entry('C:\Foo\Bar\Baz', 10) 79 | win_entry2 = Entry('D:\Program Files (x86)\GIMP', 10) 80 | win_entry3 = Entry('C:\Windows\System32', 10) 81 | 82 | @pytest.fixture 83 | def haystack(self): 84 | return [ 85 | self.entry1, 86 | self.entry2, 87 | self.entry3, 88 | self.entry4, 89 | self.entry5, 90 | ] 91 | 92 | @pytest.fixture 93 | def windows_haystack(self): 94 | return [self.win_entry1, self.win_entry2, self.win_entry3] 95 | 96 | def test_single_needle(self, haystack): 97 | assert list(match_consecutive(['baz'], haystack)) == [self.entry1, self.entry3] 98 | assert list(match_consecutive(['本'], haystack)) == [self.entry5] 99 | 100 | def test_consecutive(self, haystack): 101 | assert list(match_consecutive(['bar', 'baz'], haystack)) == [self.entry1] 102 | assert list(match_consecutive(['foo', 'bar'], haystack)) == [self.entry2] 103 | assert list(match_consecutive(['国', 'guo'], haystack)) == [self.entry4] 104 | assert list(match_consecutive(['bar', 'foo'], haystack)) == [] 105 | 106 | def test_ignore_case(self, haystack): 107 | assert list(match_consecutive(['FoO', 'bAR'], haystack, ignore_case=True)) \ 108 | == [self.entry2] 109 | 110 | def test_windows_ignore_case(self, windows_haystack): 111 | assert list(match_consecutive(['gimp'], windows_haystack, True)) == [self.win_entry2] 112 | 113 | @pytest.mark.xfail(reason='https://github.com/wting/autojump/issues/418') 114 | def test_backslashes_for_windows_paths(self, windows_haystack): 115 | assert list(match_consecutive(['program', 'gimp'], windows_haystack, True)) \ 116 | == [self.win_entry2] 117 | 118 | @pytest.mark.xfail(reason='https://github.com/wting/autojump/issues/418') 119 | def test_foo_bar_baz(self, windows_haystack): 120 | assert list(match_consecutive(['bar', 'baz'], windows_haystack, ignore_case=True)) \ 121 | == [self.win_entry1] 122 | 123 | @pytest.mark.xfail(reason='https://github.com/wting/autojump/issues/402') 124 | def test_thing(self, windows_haystack): 125 | assert list(match_consecutive(['win', '32'], windows_haystack, True)) \ 126 | == [self.win_entry3] 127 | 128 | @pytest.mark.xfail(reason='https://github.com/wting/autojump/issues/402') 129 | def test_wildcard_in_needle(self, haystack): 130 | assert list(match_consecutive(['*', 'this'], haystack)) == [] 131 | assert list(match_consecutive(['*', 'edge', 'case'], haystack)) == [self.entry6] 132 | -------------------------------------------------------------------------------- /tests/unit/autojump_utils_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | import sys 5 | 6 | import mock 7 | import pytest 8 | 9 | sys.path.append(os.path.join(os.getcwd(), 'bin')) # noqa 10 | import autojump_utils 11 | from autojump_utils import encode_local 12 | from autojump_utils import first 13 | from autojump_utils import get_tab_entry_info 14 | from autojump_utils import has_uppercase 15 | from autojump_utils import in_bash 16 | from autojump_utils import is_python3 17 | from autojump_utils import last 18 | from autojump_utils import sanitize 19 | from autojump_utils import second 20 | from autojump_utils import surround_quotes 21 | from autojump_utils import take 22 | from autojump_utils import unico 23 | 24 | 25 | if is_python3(): 26 | os.getcwdu = os.getcwd 27 | xrange = range 28 | 29 | 30 | def u(string): 31 | """ 32 | This is a unicode() wrapper since u'string' is a Python3 compiler error. 33 | """ 34 | if is_python3(): 35 | return string 36 | return unicode(string, encoding='utf-8', errors='strict') 37 | 38 | 39 | # strings 40 | @pytest.mark.skipif(is_python3(), reason='Unicode sucks.') 41 | @mock.patch.object(sys, 'getfilesystemencoding', return_value='ascii') 42 | def test_encode_local_ascii(_): 43 | assert encode_local(u('foo')) == b'foo' 44 | 45 | 46 | @pytest.mark.skipif(is_python3(), reason='Unicode sucks.') 47 | @pytest.mark.xfail(reason='disabled due to pytest bug: https://bitbucket.org/hpk42/pytest/issue/534/pytest-fails-to-catch-unicodedecodeerrors') # noqa 48 | @mock.patch.object(sys, 'getfilesystemencoding', return_value='ascii') 49 | def test_encode_local_ascii_fails(_): 50 | with pytest.raises(UnicodeDecodeError): 51 | encode_local(u('日本語')) 52 | 53 | 54 | @pytest.mark.skipif(is_python3(), reason='Unicode sucks.') 55 | @mock.patch.object(sys, 'getfilesystemencoding', return_value=None) 56 | def test_encode_local_empty(_): 57 | assert encode_local(b'foo') == u('foo') 58 | 59 | 60 | @pytest.mark.skipif(is_python3(), reason='Unicode sucks.') 61 | @mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8') 62 | def test_encode_local_unicode(_): 63 | assert encode_local(b'foo') == u('foo') 64 | assert encode_local(u('foo')) == u('foo') 65 | 66 | 67 | def test_has_uppercase(): 68 | assert has_uppercase('Foo') 69 | assert has_uppercase('foO') 70 | assert not has_uppercase('foo') 71 | assert not has_uppercase('') 72 | 73 | 74 | @mock.patch.object(autojump_utils, 'in_bash', return_value=True) 75 | def test_surround_quotes_in_bash(_): 76 | assert surround_quotes('foo') == '"foo"' 77 | 78 | 79 | @mock.patch.object(autojump_utils, 'in_bash', return_value=False) 80 | def test_dont_surround_quotes_not_in_bash(_): 81 | assert surround_quotes('foo') == 'foo' 82 | 83 | 84 | def test_sanitize(): 85 | assert sanitize([]) == [] 86 | assert sanitize([r'/foo/bar/', r'/']) == [u('/foo/bar'), u('/')] 87 | 88 | 89 | @pytest.mark.skipif(is_python3(), reason='Unicode sucks.') 90 | def test_unico(): 91 | assert unico(str('blah')) == u('blah') 92 | assert unico(str('日本語')) == u('日本語') 93 | assert unico(u('でもおれは中国人だ。')) == u('でもおれは中国人だ。') 94 | 95 | 96 | # iteration 97 | def test_first(): 98 | assert first(xrange(5)) == 0 99 | assert first([]) is None 100 | 101 | 102 | def test_second(): 103 | assert second(xrange(5)) == 1 104 | assert second([]) is None 105 | 106 | 107 | def test_last(): 108 | assert last(xrange(4)) == 3 109 | assert last([]) is None 110 | 111 | 112 | def test_take(): 113 | assert list(take(1, xrange(3))) == [0] 114 | assert list(take(2, xrange(3))) == [0, 1] 115 | assert list(take(4, xrange(3))) == [0, 1, 2] 116 | assert list(take(10, [])) == [] 117 | 118 | 119 | # environment variables 120 | def test_in_bash(): 121 | for path in ['/bin/bash', '/usr/bin/bash']: 122 | os.environ['SHELL'] = path 123 | assert in_bash() 124 | 125 | for path in ['/bin/zsh', '/usr/bin/zsh']: 126 | os.environ['SHELL'] = '/usr/bin/zsh' 127 | assert not in_bash() 128 | 129 | 130 | # helper functions 131 | def test_get_needle(): 132 | assert get_tab_entry_info('foo__', '__') == ('foo', None, None) 133 | 134 | 135 | def test_get_index(): 136 | assert get_tab_entry_info('foo__2', '__') == ('foo', 2, None) 137 | 138 | 139 | def test_get_path(): 140 | assert get_tab_entry_info('foo__3__/foo/bar', '__') \ 141 | == ('foo', 3, '/foo/bar') 142 | 143 | 144 | def test_get_none(): 145 | assert get_tab_entry_info('gibberish content', '__') == (None, None, None) 146 | -------------------------------------------------------------------------------- /tools/autojump_ipython.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | IPython autojump magic 4 | 5 | Written by keith hughitt , based on an earlier 6 | version by Mario Pastorelli . 7 | 8 | To install, create a new IPython user profile by running: 9 | 10 | ipython profile create 11 | 12 | And copy this file into the "startup" folder of your new profile (e.g. 13 | "$HOME/.config/ipython/profile_default/startup/"). 14 | 15 | @TODO: extend %cd to call "autojump -a" 16 | """ 17 | from subprocess import PIPE 18 | from subprocess import Popen 19 | 20 | from IPython.core.magic import register_line_magic 21 | 22 | ip = get_ipython() # noqa 23 | 24 | 25 | @register_line_magic 26 | def j(path): 27 | cmd = ['autojump'] + path.split() 28 | newpath = Popen( 29 | cmd, 30 | stdout=PIPE, 31 | shell=False, 32 | ).communicate()[0].strip() 33 | 34 | if newpath: 35 | ip.magic('cd %s' % newpath.decode('utf-8')) 36 | 37 | 38 | # remove from namespace 39 | del j 40 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py26, 4 | py27, 5 | py33, 6 | py34, 7 | py35 8 | # ignore missing setup.py 9 | skipsdist = True 10 | 11 | [testenv] 12 | setenv = 13 | PYTHONDONTWRITEBYTECODE = 1 14 | deps = 15 | mock 16 | coverage 17 | ipdb 18 | ipython 19 | pytest >= 2.9 20 | commands = 21 | coverage run --source=bin/ --omit=bin/autojump_argparse.py -m \ 22 | py.test -vv -rxs --tb native -s --strict {posargs:tests} 23 | coverage report -m 24 | 25 | 26 | [testenv:pre-commit] 27 | deps = 28 | pre-commit>=0.7.0 29 | commands = 30 | pre-commit {posargs} 31 | 32 | [pytest] 33 | norecursedirs = .git .tox docs 34 | -------------------------------------------------------------------------------- /uninstall.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | 5 | import os 6 | import platform 7 | import shutil 8 | import sys 9 | 10 | sys.path.append('bin') 11 | from autojump_argparse import ArgumentParser # noqa 12 | 13 | 14 | def is_empty_dir(path): 15 | """ 16 | Checks if any files are present within a directory and all sub-directories. 17 | """ 18 | for _, _, files in os.walk(path): 19 | if files: 20 | return False 21 | return True 22 | 23 | 24 | def parse_arguments(): 25 | default_clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink') 26 | 27 | parser = ArgumentParser( 28 | description='Uninstalls autojump.', 29 | ) 30 | parser.add_argument( 31 | '-n', '--dryrun', action='store_true', default=False, 32 | help='simulate installation', 33 | ) 34 | parser.add_argument( 35 | '-u', '--userdata', action='store_true', default=False, 36 | help='delete user data', 37 | ) 38 | parser.add_argument( 39 | '-d', '--destdir', metavar='DIR', 40 | help='custom destdir', 41 | ) 42 | parser.add_argument( 43 | '-p', '--prefix', metavar='DIR', default='', 44 | help='custom prefix', 45 | ) 46 | parser.add_argument( 47 | '-z', '--zshshare', metavar='DIR', default='functions', 48 | help='custom zshshare', 49 | ) 50 | parser.add_argument( 51 | '-c', '--clinkdir', metavar='DIR', default=default_clink_dir, 52 | ) 53 | 54 | return parser.parse_args() 55 | 56 | 57 | def remove_custom_installation(args, dryrun=False): 58 | if not args.destdir: 59 | return 60 | 61 | bin_dir = os.path.join(args.destdir, args.prefix, 'bin') 62 | doc_dir = os.path.join(args.destdir, args.prefix, 'share', 'man', 'man1') 63 | etc_dir = os.path.join(args.destdir, 'etc', 'profile.d') 64 | share_dir = os.path.join(args.destdir, args.prefix, 'share', 'autojump') 65 | zshshare_dir = os.path.join(args.destdir, args.zshshare) 66 | 67 | if not os.path.exists(share_dir): 68 | return 69 | 70 | print('\nFound custom installation...') 71 | rm(os.path.join(bin_dir, 'autojump'), dryrun) 72 | rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun) 73 | rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun) 74 | rm(os.path.join(bin_dir, 'autojump_argparse.py'), dryrun) 75 | if platform.system() == 'Windows': 76 | if os.path.exists(args.clinkdir): 77 | rm(os.path.join(args.clinkdir, 'autojump.lua'), dryrun) 78 | rm(os.path.join(bin_dir, 'autojump.bat'), dryrun) 79 | rm(os.path.join(bin_dir, 'j.bat'), dryrun) 80 | rm(os.path.join(bin_dir, 'jc.bat'), dryrun) 81 | rm(os.path.join(bin_dir, 'jco.bat'), dryrun) 82 | rm(os.path.join(bin_dir, 'jo.bat'), dryrun) 83 | else: 84 | rm(os.path.join(etc_dir, 'autojump.sh'), dryrun) 85 | rm(os.path.join(share_dir, 'autojump.bash'), dryrun) 86 | rm(os.path.join(share_dir, 'autojump.fish'), dryrun) 87 | rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun) 88 | rm(os.path.join(share_dir, 'autojump.zsh'), dryrun) 89 | rm(os.path.join(zshshare_dir, '_j'), dryrun) 90 | rmdir(share_dir, dryrun) 91 | rm(os.path.join(doc_dir, 'autojump.1'), dryrun) 92 | 93 | if is_empty_dir(args.destdir): 94 | rmdir(args.destdir, dryrun) 95 | 96 | 97 | def remove_system_installation(dryrun=False): 98 | default_destdir = '/' 99 | default_prefix = '/usr/local' 100 | default_zshshare = '/usr/share/zsh/site-functions' 101 | 102 | bin_dir = os.path.join(default_destdir, default_prefix, 'bin') 103 | doc_dir = os.path.join( 104 | default_destdir, 105 | default_prefix, 106 | 'share', 107 | 'man', 108 | 'man1', 109 | ) 110 | etc_dir = os.path.join(default_destdir, 'etc', 'profile.d') 111 | share_dir = os.path.join( 112 | default_destdir, 113 | default_prefix, 114 | 'share', 115 | 'autojump', 116 | ) 117 | zshshare_dir = os.path.join(default_destdir, default_zshshare) 118 | 119 | if not os.path.exists(share_dir): 120 | return 121 | 122 | print('\nFound system installation...') 123 | 124 | if os.geteuid() != 0: 125 | print( 126 | 'Please rerun as root for system-wide uninstall, skipping...', 127 | file=sys.stderr, 128 | ) 129 | return 130 | 131 | rm(os.path.join(bin_dir, 'autojump'), dryrun) 132 | rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun) 133 | rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun) 134 | rm(os.path.join(etc_dir, 'autojump.sh'), dryrun) 135 | rm(os.path.join(share_dir, 'autojump.bash'), dryrun) 136 | rm(os.path.join(share_dir, 'autojump.fish'), dryrun) 137 | rm(os.path.join(share_dir, 'autojump.tcsh'), dryrun) 138 | rm(os.path.join(share_dir, 'autojump.zsh'), dryrun) 139 | rm(os.path.join(zshshare_dir, '_j'), dryrun) 140 | rmdir(share_dir, dryrun) 141 | rm(os.path.join(doc_dir, 'autojump.1'), dryrun) 142 | 143 | 144 | def remove_user_data(dryrun=False): 145 | if platform.system() == 'Darwin': 146 | data_home = os.path.join( 147 | os.path.expanduser('~'), 148 | 'Library', 149 | 'autojump', 150 | ) 151 | elif platform.system() == 'Windows': 152 | data_home = os.path.join( 153 | os.getenv('APPDATA'), 154 | 'autojump', 155 | ) 156 | else: 157 | data_home = os.getenv( 158 | 'XDG_DATA_HOME', 159 | os.path.join( 160 | os.path.expanduser('~'), 161 | '.local', 162 | 'share', 163 | 'autojump', 164 | ), 165 | ) 166 | 167 | if os.path.exists(data_home): 168 | print('\nFound user data...') 169 | rmdir(data_home, dryrun) 170 | 171 | 172 | def remove_user_installation(dryrun=False): 173 | if platform.system() == 'Windows': 174 | default_destdir = os.path.join( 175 | os.getenv('LOCALAPPDATA', ''), 176 | 'autojump', 177 | ) 178 | clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink') 179 | else: 180 | default_destdir = os.path.join(os.path.expanduser('~'), '.autojump') 181 | 182 | if os.path.exists(default_destdir): 183 | print('\nFound user installation...') 184 | rmdir(default_destdir, dryrun) 185 | if platform.system() == 'Windows' and os.path.exists(clink_dir): 186 | rm(os.path.join(clink_dir, 'autojump.lua'), dryrun) 187 | 188 | 189 | def rm(path, dryrun): 190 | if os.path.exists(path): 191 | print('deleting file:', path) 192 | if not dryrun: 193 | os.remove(path) 194 | 195 | 196 | def rmdir(path, dryrun): 197 | if os.path.exists(path): 198 | print('deleting directory:', path) 199 | if not dryrun: 200 | shutil.rmtree(path) 201 | 202 | 203 | def main(args): 204 | if args.dryrun: 205 | print('Uninstalling autojump (DRYRUN)...') 206 | else: 207 | print('Uninstalling autojump...') 208 | 209 | remove_user_installation(args.dryrun) 210 | remove_system_installation(args.dryrun) 211 | remove_custom_installation(args, args.dryrun) 212 | if args.userdata: 213 | remove_user_data(args.dryrun) 214 | 215 | 216 | if __name__ == '__main__': 217 | sys.exit(main(parse_arguments())) 218 | --------------------------------------------------------------------------------