Anonymous avatar Anonymous committed 160a320

added article on 2

Comments (0)

Files changed (1)

+title: the power of 2
+keywords: cd, chdir, unix, shell, bash, golang, autojump, CDPATH, zsh, alias
+"2" helps you to jump between folders in your unix shell.
+It's just my attempt to _guess_ where you want to navigate
+and help you with less typing.
+how it works
+Here's a [screencast]( to see what I'm talking about.
+A tiny script integrated with your shell populates the directories database
+while you are jumping around.
+Later, when you want to `cd` somewhere you just type a few letters (hints) -
+"2" will find the most suitable directory path using the fuzzy search and
+brings you there.
+If you want to know more - "2" has two parts (what a coincidence!).
+The first is a piece of a shell script (now `zsh` and `bash` are supported).
+This scripts monitors your moves around the filesystem tree and
+provides and alias for "2" and a hotkey for interactive mode (see below what
+it means).
+The second piece is a tool written in Go. It reads and writes the directories
+database and performs the actual search. The reasons I added a separate
+tool is to optimize search speed. But to tell you the truth - I didn't want
+to torture myself with writing a search algorithm in Bash :)
+	$ hg clone ssh://
+	$ cd 2
+	$ go build
+	$ sudo cp 2 /usr/local/bin
+	$ sudo mkdir /usr/local/share/2
+	$ sudo cp bashrc /usr/local/share/2
+	$ sudo cp zshrc /usr/local/share/2
+Then add the following lines to your `.bashrc` or `.zshrc` depending on what
+shell you use:
+	export _2IGNORE="/tmp/*"
+	source /usr/local/share/2/bashrc # or zshrc
+The second line integrates "2" into your shell and the first line
+is used to configure it (to make it ignore some paths)
+If you want "2" to understand you better first set up the ignored paths.
+I personally don't like it to remember my `/tmp` and all its subfolders
+because they are located in the `tmpfs` and there is no sense to store these
+paths in the persistent database. Also, I don't want it to remember my home
+directory (but still remember the subdirectories). 
+You can put a list of ignored paths into the `_2IGNORE` environment variable
+separated by colons. In my case it looks like:
+	export _2IGNORE="/tmp/*:/home/serge"
+The star at the end of the path means a mask.
+Next, the hints that are closer to the end of the path are more important, thus
+for hint `"sys"` it's more likely to go to `/usr/include/sys` than to
+	`/sys/kernel/debug`.
+Hints are matched in the order you type them. 
+Another thing to remember is that extra importance have hints that match the
+parts of the path after the separators: hint `"inc"` points `/usr/include`
+more obviously than hint `"clu"` even though `"clu"` is closer to the end of
+the path.
+That's all you need to know. Happy "2"-ing!
+interactive mode
+If you want to see what path matches your hints the best you can try
+interactive mode. It's still in its very early days, but might help someone.
+To activate interactive mode type Ctrl+2 in zsh or Alt+2 in bash.
+other info
+"2" is an open source software and is distributed under MIT license.
+The sources are hosted on [Bitbucket](
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.