• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command line tool to find alternate files

Alt

alt is a command line utility that finds the "alternate paths" for the provided path.

alt [OPTIONS] PATH

alt finds alternate file paths for the given PATH based on a similarity ranking. For example, if you were in a Ruby project and ran alt spec/app/queues/fee/user_fee_submission_spec.rb the output would include ranked at the top app/queues/fee/user_fee_submission.rb. In this case the alternate for the test file is the implementation file. It is important to understand that alternate files are simply filenames and paths that rank high in similarity.

alt by default outputs all possible alternate paths in ranked order. In older major versions the behavior was to only output the highest ranked file path. To retain this behavior simply use the truncate option with a value of 1.

This is primarily intended for developers. It is written in Rust. Hence, it is compiled and distributed as a binary.

It was originally written to alternate files in vim, but has no dependency on vim at all and can be used in many other scenarios as it is just a command line utility.

Its interface is as simple as they come.

  • Pass it a path as the first argument
  • It will print the alternate paths in ranked order on separate lines via standard out

For example:

$ alt spec/app/queues/fee/user_fee_submission_spec.rb
app/queues/fee/user_fee_submission.rb
app/bar/car/user_goal.rb
app/queues/modification/vehicle.rb

Demo

For advanced usage & full reference of the command line interface, please refer to the man page via man alt.

Installation

If you are on a platform other than macOS or Arch Linux you will have to build your own version from source.

macOS

To install on macOS we provide a Homebrew tap which provides the alt formula. You can use it by doing the following:

Add the Tap

brew tap "uptech/homebrew-oss"

brew install

brew install uptech/oss/alt

Arch Linux

Install from the AUR:

git clone https://aur.archlinux.org/alt.git
cd alt
makepkg -si

Build from Source

If you are on another platform you will have to build from source. Given that alt is managed via Rust's Cargo. It can build as follows:

$ cargo build --release

Once you have built it successfully you should relocate the target/release/alt binary to a location that exists in your PATH so that you can easily use it. You should also relocate the doc/alt.1 man page to the appropriate location.

Note: The above requires of course that you have rust and Cargo.

Use with NeoVim

There's no NeoVim or Vim plugin. It may not end up needing one; we will see. The snippet below is a basic setup I use in my NeoVim to tie alt into telescope so that I can fuzzy select the ranked alternate paths. For now, you can just stick the code below in your init.lua to invoke alt with <leader>. Note that alt and the NeoVim Lua example below work in both the terminal based NeoVim and GUI based NeoVim.

-- ----------------------------------------------
-- Alternate File Switching
-- ----------------------------------------------
local pickers = require "telescope.pickers"
local finders = require "telescope.finders"
local conf = require("telescope.config").values

local alternates_picker = function(alternates, opts)
  opts = opts or {}
  pickers.new(opts, {
	prompt_title = "alternates",
	finder = finders.new_table {
	  results = alternates
	},
	sorter = conf.generic_sorter(opts),
  }):find()
end

function alt(path)
  local function isempty(s)
	return s == nil or s == ''
  end

  -- This is where you can configure it with CLI options so
  -- it behaves how you want it to.
  local alternates = vim.fn.system("some/path/alt " .. path)
  if isempty(alternates) then
	return nil
  else
	local alternates_table = {}
	for s in alternates:gmatch("[^\r\n]+") do
	  table.insert(alternates_table, s)
	end
	return alternates_table
  end
end

function alt_command(path, alt_handler)
  local current_file_path = vim.fn.expand('%')
  local alternate_file_paths = alt(current_file_path)
  if alternate_file_paths == nil then
	print("No alternate files found for " .. current_file_path .. "!")
  else
	alt_handler(current_file_path, alternate_file_paths)
  end
end

function alt_handler(current_file_path, alternate_file_paths)
  alternates_picker(alternate_file_paths)
end

vim.keymap.set('n', '<leader>.', function()
  alt_command(vim.fn.expand('%'), alt_handler)
end)

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.

Contributing

If you interested at all in contributing. Please do. We are a welcoming group and are willing to provide guidance whenever possible.

Please see CONTRIBUTING.md for more details on contributing.

License

alt is Copyright © 2016 - 2023 UpTech Works, LLC. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About Uptech Studio

alt is maintained and funded by Uptech Studio, a software design & development studio.

We love open source software. See our other projects or hire us to design, develop, and grow your product.

More Repositories

1

sublime_guard

Sublime Text 2 Guard Plugin - helps create a smoother development workflow.
Python
175
star
2

git-ps-rs

Official git-ps Rust implementation - the future of git-ps
Rust
78
star
3

git-ps

Patch Stack workflow CLI extension for Git
Swift
50
star
4

togls

An ultra light weight yet ridiculously powerful Ruby feature toggle gem
Ruby
23
star
5

git-cl

Git command line tool for managing your CHANGELOG with defined schema entries in your commits
Swift
23
star
6

octopusci

A multi-branch continuous integration server
Ruby
19
star
7

vim-open-alternate

Vim plugin that makes it trivial to jump between alternate files (test files & implementation, etc.)
Vim Script
11
star
8

Constraid

Your friendly NSLayoutConstraint Aid
Swift
11
star
9

flutter_forge

This is the beginnings of the flutter_riverpod_composable_arch and a sample app to play around with it.
Dart
6
star
10

tmuxme

Offical repo has moved to
Ruby
6
star
11

snapdragon

A Jasmine JavaScript test runner that lets you run tests on the command-line similar to RSpec.
JavaScript
6
star
12

Flot

Flot (a pure Javascript plotting library for jQuery) with additional features (multi-series bar graphs, etc).
JavaScript
5
star
13

vim-ping-cursor

Vim plugin to help you quickly locate the cursor position
Vim Script
5
star
14

git-ps-book

The official Git Patch Stack Book
5
star
15

mailmate_stylesheets

My Personal MailMate Stylesheets
CSS
4
star
16

jquery-sliders-rails

Gem that provides the jQuery Sliders plugin to Rails 3 apps
Ruby
4
star
17

vim-slack-format

Vim plugin providing the slack file type and syntax highlighting support for it
Vim Script
4
star
18

boxci

Tool to simplify create virtual development environments and cloud based CI jobs
Ruby
4
star
19

libgnutmsgs

A unix C implementation of the Gnutella protocol designed to test ad injection on the network.
C
3
star
20

dotzsh

My zsh setup (.zshrc and helper scripts)
Shell
3
star
21

archaic

IRC Chat Archiving and Analysis Tool
Ruby
3
star
22

tmuxme_client

Offical repo has moved to
Ruby
2
star
23

dotnvim

My personal neovim dot files.
Lua
2
star
24

dotack

Dot files for my ack setup, primarily ~/.ackrc
2
star
25

tagalong

A Rails tagging plugin that makes sense. ( Note: has built in support for Sunspot for search )
Ruby
2
star
26

jquery_comp_hist

jQuery Comparative Histogram plugin. Often used for demographics.
JavaScript
2
star
27

gnuautotools-tmbundle

GNU Autotools TextMate Bundle
Shell
2
star
28

dotvim

My personal Vim dot files (.vimrc, .vim dir, vim plugins, etc.)
Ruby
2
star
29

git-tools

This repo is to house git tools we whip up
Shell
2
star
30

trac_embed_gitweb

Trac 0.11 plugin to embed gitweb inside the Browse Source tab.
Python
2
star
31

pra

The command line (ncurses) based pull request aggregator
Ruby
2
star
32

jquery_sliders

A simple very generic jQuery slideshow plugin
JavaScript
2
star
33

trac_ticket_creator

Trac XmlRpcPlugin Front-end for creating tickets more fluidly.
Python
2
star
34

libgnut

A cross-platform implementation of the Gnutella protocol.
C
2
star
35

dottmux

My personal tmux dot files.
Shell
1
star
36

activerecord_history

An extension to active record that allows tracking of changes to database entities.
Ruby
1
star
37

skiplist_applet

A small Java applet that I wrote to assist in teaching skip lists.
Java
1
star
38

usurper_applet

PDF Flash Card Quizing Applet for Gnome
C
1
star
39

opensync_zdtm_plugin

This provides the OpenSync framework an interface to lib_zdtm_sync to allow syncing.
C
1
star
40

zync

A command line tool to synchronize the Zaurus. (obsolete)
C++
1
star
41

podcasts

Current state of the podcasts listen to and videos I watch
1
star
42

zync_korg_todo_plugin

A KOrganizer plugin interfaced with zync. (obsolete)
C++
1
star
43

zync-gui

A graphical user interface to zync. (obsolete)
C++
1
star
44

th-deckjs-template

ThoughtHatchery deck.js template
JavaScript
1
star
45

lib_zdtm_docs

LaTeX source and other documentation we have written for the lib_zdtm_sync project.
Shell
1
star
46

lifecyclemanager

Trac plugin for Tracking & Managing the Lifecycle of Software Projects
Python
1
star
47

alt-archlinux-builder

Dockerfile and source for the alt-archlinux-builder Docker image
1
star
48

lib_zdtm_sync

A cross-platform library to speak the Zaurus synchronization protocol. It provides an interface to parse and create the packets sent to and received from the Zaurus.
C
1
star