alt

attempts to find "alternate" for path

SYNOPSIS

alt [OPTIONS] PATH

DESCRIPTION

alt finds the alternate file for the given PATH based on similarity ranking. For example, if you were in a Ruby project and ran alt spec/app/queues/fee/user_fee_submission_spec.rb it would output app/queues/fee/user_fee_submission.rb. In this case the alternate for the test file is the implementation file.

OPTIONS

-v, --version

Output the version of alt

-h, --help

Output the usage help

-a

Include directory entries whose names begin with a dot

-f file, --file file

Read possible alternates from a file rather than using the default directory walk technique built into alt. If file is "-" it will read the possible alternates from stdin. The following is an example of using find, a very common command line utility, to produce a filtered set of paths and pass them to alt:

find . -path tags -prune -or -path ./log -prune -or -type f -print | alt -f - spec/lib/foo/api_spec.rb

In the above example it excludes tags and log file paths from the possible alternate paths and passes the rest into alt. Note: This example is less performant than the built in directory walk technique and it's filtering. It is simply an example of how you can pass output from one command line tool to alt as input.

USE WITH VIM

There's no vim plugin. It may not end up needing one; we'll see. For now, you can just stick the code below in your .vimrc to invoke alt with <leader>. Note that alt and the Vim Script example below work in both the terminal based Vim and GUI based Vim like MacVim.

" Run a given vim command on the results of alt from a given path. " See usage below. function! AltCommand(path, vim_command) let l:alternate = system("alt " . a:path) if empty(l:alternate) echo "No alternate file for " . a:path . " exists!" else exec a:vim_command . " " . l:alternate endif endfunction

" Find the alternate file for the current path and open it nnoremap <leader>. :w<cr>:call AltCommand(expand('%'), ':e')<cr>

IGNORING THINGS

alt by default ignores hidden directory entries, globs defined in a .ignore file and globs defined in your project's .gitignore and your global .gitignore. It does this because in our experience that is generally the behavior you want. If however you want for example to be able to alternate between hidden files for some reason, you can always use the -a option. If you want to have alt ignore some specific paths/files that you don't want Git to ignore. You can simply define them in the .ignore file at the root of your project.

COPYRIGHT

Copyright (c) 2016-2018 UpTech Works, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

AUTHOR

Originally written by Andrew De Ponte <cyphactor@gmail.com>.

Copied to clipboard