11 ms·
Quickly navigate your filesystem from the command line
- nkuttler 13y agoThat looks clever and useful, I wasn't expecting that. I do maintain a few aliases to jump around, but this looks more efficient. Not sure though if I'll like "jump foo" better than simply "foo" that I use now, but maintaining those aliases is a pita.
- straphka 13y agoThis does look very similar to the setup I am using (https://github.com/huyng/bashmarks https://github.com/huyng/bashmarks)
- anjanb 13y agocool! I'm a command-line junkie as well. So, I've been doing something similar for quite a while. Here's what I have done : function ccb () { FOO=`pwd`; echo >> ~/shortcuts.sh; echo alias $1=\'pushd $FOO\' >> ~/shortcuts.sh; echo >> ~/shortcuts.sh; . ~/shortcuts.sh } simple but quite effective. Now, all I have to do is type ccb and give a shortcut name to register a shortcut. Then whenever i want to jump to that directory, I just have to type the shortcut. Eg : foo@bar deeply-nested-dir# ccb deepd foo@bar deeply-nested-dir# cd foo@bar ~# deepd foo@bar deeply-nested-dir# My method lacks the a) delete shortcut and b) list shortcut features that the above solution gives, though.
- IanCal 13y agoHN uses markdown, stick 4 spaces before each line in your code blocks to get them to indent properly, and drop the <br> function ccb () { FOO=`pwd`; echo >> ~/shortcuts.sh; echo alias $1=\'pushd $FOO\' >> ~/shortcuts.sh; echo >> ~/shortcuts.sh; . ~/shortcuts.sh }
- anjanb 13y agothanks for letting me know -- I've edited my comment.
- noisy_boy 13y agoSo interesting since I've been using pratically the SAME idea for over an year now :D Shows how we arrive at nice solutions independently. PS: I assume you are calling shortcuts.sh in your .profile - that way aliases are available across sessions.
- anjanb 13y agoyes. I call shortcuts.sh from my .bashrc
- sam152 13y agoThis is really neat. I have added it to alias.sh for easy inclusion: http://alias.sh/filesystem-markers-jump http://alias.sh/filesystem-markers-jump
- fau 13y agoYou might want to check out z: https://github.com/rupa/z https://github.com/rupa/z
- wereHamster 13y agoz is so much more useful because it automatically learns which paths you use most often. There is no need to explicitly mark folders. It just works.
- rishigoutam 13y agoHow does it differ from autojump?
- wereHamster 13y agoI don't know autojump, but from a cursory look: z is written in pure shell, is a single file, no external dependencies. autojump requires python, thus likely has more features. IMHO, just for jumping around directories, z is good enough.
- masnick 13y ago+1 for z. It's the primary way I navigate between folders at the command line.
- moonlighter 13y agoThank you! Glad I read the comments first... seems like z is more powerful yet easier to use. Ended up installing that.
- TheEskimo 13y agohttps://github.com/clvv/fasd https://github.com/clvv/fasd I used to use z, but I've since switched to fasd. It's much like z, but also so much better. In addition to being able to do "z <part of directory>" you can do "f <part of file>". So, for example, if I've got a rails project I've worked on a lot recently I know its config.ru is high on frecency, so I'll just do "vim `f config`" to edit that file. If I want a file that's not so recent I can always do "vim `f -i config`" to pick from a list of files. fasd is leaps and bounds above z in functionality, and I've thoroughly enjoyed using it.
- th0br0 13y agoOr you might just use ZSH (particularly in combination with oh-my-zsh), keep the marks around as zsh vars and skip all the symbolic linkage.
- tiziano88 13y agothis way they would all be lost at the end of each session, and would not be shared across concurrent sessions, no?
- roob 13y agoI also do something similar but slightly different: https://github.com/roobert/dotfiles/blob/master/.zsh/robs/functions/bookmarks.zsh https://github.com/roobert/dotfiles/blob/master/.zsh/robs/fu... my method involves storing the bookmarks in a file but loading them into zshs directory hash. This means the directories are tab completable and if you have AUTO_CD set then you can change directory with simply: ~dir_name, otherwise: cd ~dir_name.
- belovedeagle 13y agoAnd with CDABLE_VARS set, you can simply do: dir_name In fact, you don't even have to use the directory hash for this, you just do, e.g.: MY_DIR=/path/to/dir; MY_DIR Frankly, this is far superior to the linked method.
- roob 13y agoExcept tab completion is annoying since zsh will include commands and environment variables in its guesses. The linked method simply provides a way to store the directory hash across sessions.
- modernerd 13y agoI had to modify Jeroen's code to get the `marks` shortcut working under Mac OS 10.8: export MARKPATH=$HOME/.marks function jump { cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1" } function mark { mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 } function unmark { rm -i $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- && echo }
- guygurari 13y agoHere is another version of 'marks' for Mac OS that aligns the arrows. It also works when 'ls' is aliased. function marks { \ls -l $MARKPATH | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}' }
- 0x09 13y agoIf you are on a system with BSD stat like OS X you can get the same with function marks { (cd $MARKPATH && stat -f"%-10SN%SY" *) } Even better with column (t="$(printf "\t")"; cd $MARKPATH && stat -f"%N$t%SY" * | column -ts"$t")
- flyswatter 13y agoOne more fix... if you have group names with spaces this will throw the field number off and you'll see the modification time preceding the mark name. Adding '-n' to the ls command works around this by causing the group id to be printed instead of the group name and all works, i.e.: \ls -ln "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}'
- beders 13y agoAnd here's a completion code that works for Mac OS: function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l | awk -F '/' '{print $NF}') COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump jump
- AlexanderDhoore 13y agoA handy alias I use: alias ..='cd ..' Moving up the file tree has never been easier!
- hk__2 13y agoPut the following in your .bashrc instead: shopt -s autocd If you type a directory in the command-line, it’ll cd into it, e.g.: $ .. # cd .. $ ~ # cd ~ $ foo # cd foo I can’t live without this.
- AlexanderDhoore 13y agoVery cool, thanks! Although: On OS X: "-bash: shopt: autocd: invalid shell option name" Apple and their outdated tools... It gets annoying after a while.
- rangibaby 13y agoInstall new bash using brew :-) (1) http://apple.stackexchange.com/questions/55412/cd-to-a-directory-by-typing-its-name http://apple.stackexchange.com/questions/55412/cd-to-a-direc...
- binofbread 13y agoI believe this is set by default in oh-my-zsh as well.
- cgore 13y agoIn Zsh, you can set it so that specifying a bare directory goes to the directory as well, for any directory. Just do setopt autocd
- xal 13y agobrew install fasd Thank me later
- networked 13y agoYou can also use ranger [1] to change directories, especially if you want to explore the directory tree quickly when you don't know exactly where to jump to. Install it and add the following to ~/.bashrc: function ranger-cd { tempfile='/tmp/chosendir' /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd -- "$(cat "$tempfile")" fi rm -f -- "$tempfile" } # This binds Ctrl-O to ranger-cd: bind '"\C-o":"ranger-cd\C-m"' (This script comes from the man page for ranger(1).) Edit: Modified the above script for use with zsh (and multiple users): ranger-cd() { tempfile=$(mktemp) ranger --choosedir="$tempfile" "${@:-$(pwd)}" < $TTY test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd -- "$(cat "$tempfile")" fi rm -f -- "$tempfile" } # This binds Ctrl-O to ranger-cd: zle -N ranger-cd bindkey '^o' ranger-cd [1] http://ranger.nongnu.org/ http://ranger.nongnu.org/.
- braum 13y agothanks! I tried: apt-get install ranger it says it's not available. any idea why ranger is not longer available in package manager?
- networked 13y agoWhat is your distribution? I've just tried it and it's available in both Ubuntu 12.04 and Debian 7. The launchpad page says that it should be in later Ubuntu releases, too. Enable the "universe" repository then run apt-get update and see if it fixes the problem.
- verbatim 13y agoInteresting idea. I've the bash built-in "pushd" and "popd" for a long time for similar reasons, but those effectively limit you to treating the history as a stack rather than an arbitrary list.
- yummysoup 13y agoyeah, it can be annoying that the directory stack sequence keeps changing, which means that sometimes you can't easily re-run commands from your history if you've pushd since you last ran the command e.g., a command like "tar cfz bak.tgz ~3 ~2/subdirectory ~1" would mean something else once you've "pushd +3". I always find it hard to undo my sequence changes to get the stack in the same order as before, so usually end up typing "dirs -v" a lot (or its alias) and renumbering my ~N references.
- Thrysoee 13y agoI frequent systems where tcsh, for historical reasons, is the default shell, and for all its faults it does have some nice pushd settings that make directory browsing with 'cd +<number>' and 'dirs' very convenient. I have ported this functionality to Bash: http://thrysoee.dk/pushd/ http://thrysoee.dk/pushd/
- davejamesmiller 13y agoI'm too lazy to type "jump" so I've modified it to automatically add a Bash alias for each one as well. https://github.com/davejamesmiller/dotfiles/blob/master/.bash/mark.bash https://github.com/davejamesmiller/dotfiles/blob/master/.bas...
- nkuttler 13y agoUnless I'm missing something you also need a function to create all aliases when the shell session starts?
- davejamesmiller 13y agoThat's what the for loop at the bottom does.
- nkuttler 13y agodoh!
- mynameisfiber 13y agoI found this is a useful addition to his scripts... I can't live without my tab completion! _jump() { local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $(compgen -W "$( ls $MARKPATH )" -- $cur) ) } complete -F _jump jump
- sgt 13y agoCleaner than the other variants here that use "find".
- nkuttler 13y agoTo have completion with bash you can use this: function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l -printf "%f\n") COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump jump Bash completion really needs better docs :-|
- Lifescape 13y agoI was in the process of doing this myself and though "I wonder if it's already been posted in the comments". Thank you!
- aaren 13y agoI just signed in to post almost exactly this function!
- christiangenco 13y agoHmmm, this doesn't seem to work in `zsh`. Typing `jump <tab>` suggests everything in the current directory (folders and files). Does anyone here know offhand how autocompletion in `zsh` works?
- lazerwalker 13y agoI've been using Bashmarks (https://github.com/huyng/bashmarks https://github.com/huyng/bashmarks) for years, which appears to be basically the same thing but with a less verbose interface.
- manojlds 13y agoAnd poshmarks for those on Windows - https://github.com/manojlds/poshmarks https://github.com/manojlds/poshmarks
- tiziano88 13y agoCool, simple but very useful! Bonus: if you want autocompletion for the jump and unmark commands, just add the following lines (in zsh): function _marks { reply=($(ls $MARKPATH)) } compctl -K _marks jump compctl -K _marks unmark
- ddoolin 13y agoI usually just alias directories I frequent in .bashrc... Easy enough, I guess.
- cgore 13y agoI'll do it all the time in my local shell session, along the following: # I make a point to always have the trailing slash, # it makes life easier. # Also, tab-complete works with this in Zsh. a=/some/really/long/path/that/I/dont/like/typing/ b=/some/other/really/long/path/too/ cd $a # ... do stuff ... cp one two three $b cd $b # ... do more stuff ... cp four five six $a cd $b/even/longer/path And so forth. Since it is a normal variable, you can use it anywhere you need the path.
- timtadh 13y agoI have a similar tool but it also manages shell environment variables, allowing you to jump around and/or switch working projects. You can check it out at: http://github.com/timtadh/swork http://github.com/timtadh/swork
- mhitza 13y agoWithout having me dig through the code, could you tell me in a few lines how it works? (not usage, but how internally you managed to handle shell environment vars, "clean after" finishing/switching, etc)
- _mc 13y agoCool!, I usually want to open a new terminal window and move to the same directory I am working in, I use these handy aliases : alias here='pwd | pbcopy' alias there='cd $(pbpaste)' So now type `here` in current terminal window and type `there` in new terminal window to move to same directory! [This works on Mac on other OS you could use xcopy or equivalent clipboard copy program]
- jijji 13y agoNot sure if the author knows or not, but there exists a BASH environment variable called CDPATH which does the same thing, and is a lot easier to use.
- nodata 13y agohttp://hints.macworld.com/article.php?story=2005031814311425 http://hints.macworld.com/article.php?story=2005031814311425
- clumsysmurf 13y agoThis reminds me of NCD (Norton Change Directory) which then went on to inspire many tools, like the excellent KCD and WCD. These tools index rather than create symlinks, though.
- sukaka 13y agoReminds me of z, which I use all the time. Anyone else use z? If you have not heard of it, get it now https://github.com/rupa/z https://github.com/rupa/z. z is a wonderful complement to cd. After cd into a folders with z set up, a file stores all folders navigated to sorted by frecency, then simply jump to a folder with z [foldernameregex].
- dmd 13y agoz is absolutely wonderful. Even my boss has become a convert, and he's been hacking unix since the 1970s, when he worked at AT&T, and is very set in his ways. [Disclaimer: rupa's a good friend of mine]
- grimgrin 13y agoI've converted a few people to the z side. And yes, it is wonderful. [Disclaimer: rupa is a good friend of mine, as well]
- Fuzzwah 13y agoI was pretty excited about original link in this HN submission, but now I'm roughly twice as excited to learn about z. Love it. [Disclaimer: I don't know rupa at all]
- baohaojun 13y agoI have developed a very similar scheme for myself independently (haven't heard of z before, but thanks). A further idea is another command <code>e</code>, which is used like: <code>e reg1 reg2...</code>, and it will query z's database to see if there is a file in z's directory which matches the regs, and if found, open that file in Emacs. A similar command <code>f</code> will only print the path, so that <code>firefox $(f reg1 reg2)</code> will open the found file using firefox.
- franzb 13y agoHere is a fully functional (albeit minimal) Windows version: http://appleseedhq.net/stuff/marks-v1.zip http://appleseedhq.net/stuff/marks-v1.zip. Tested on Windows 7 (does not require PowerShell). GitHub: https://github.com/dictoon/marks https://github.com/dictoon/marks Edit: to install, unzip anywhere and add to your path. Then: C:\Windows> mark win C:\Windows> marks win => C:\Windows C:\Windows> cd .. C:\> jump win C:\Windows> Marks will be stored in a marks\ subdirectory (relatively to the mark.bat file).
- shailesh 13y agoClever! With fish 2.0, the shell stores a list of "cd" commands issued from a specific directory, so mostly just typing "cd" yields an auto-completion hint out of the box.
- jasminaata 13y agoHere is one that works with zsh: https://github.com/bufordtaylor/swiftcommandline https://github.com/bufordtaylor/swiftcommandline
- arrowgunz 13y agoTry using https://github.com/rupa/z https://github.com/rupa/z
- deleted 13y ago[deleted]
- microcolonel 13y agoI set my version up with a -f on the unmark rm so that I don't need to be prompted to remove it. Also added some basic completion for both jump and unmark export MARKPATH=$HOME/.marks function jump { cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1" } function mark { mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1 } function unmark { rm -if $MARKPATH/$1 } function marks { ls -l $MARKPATH | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo } _completemarks() { local curw=${COMP_WORDS[COMP_CWORD]} local wordlist=$(find $MARKPATH -type l -printf "%f\n") COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw")) return 0 } complete -F _completemarks jump unmark
- DigitalJack 13y agoI recommend avoiding -f on rm if you can. Make one mistake and it can be painful. In this case think removing the -i from the unmark function will accomplish what you want. I made something to the OP's system for the same reason of disdain for super deep trees at work. I'll make a gist and edit this post with it in a few minutes. Edit: https://gist.github.com/desertmonad/6258429 https://gist.github.com/desertmonad/6258429 I like the OP's idea of using symbolic links. That makes it more generally useful (i.e. a gui app can use those simple paths too). I may switch over to that.
- likeclockwork 13y agoWhy not use unlink?
- DigitalJack 13y agoWhat's the advantage?
- coherentpony 13y agoThe purpose of the -i flag is to prompt the user before deleting. Mixing the -i and -f flags is a little moot. Try removing the -i option to obtain what you want.
- skrebbel 13y agoFor Windows users I have a closely related shameless plug: cdhere navigates your cmd.exe to wherever the current topmost Explorer window is pointed at. It's not the same as the OP's trick, of course, but since you're voluntarily using Windows, I'm going to assume you "live" on the command line less than the average UNIX user, and more on GUI tools such as good old Explorer. https://github.com/eteeselink/cdhere https://github.com/eteeselink/cdhere
- ams6110 13y agoYou could install cygwin and use the OP technique, though.
- tripzilch 13y agounfortunately cygwin takes a lot longer to start than cmd, so I use it only occasionally. are there any fixes for that maybe? :)
- keyboardP 13y agoYou can hold shift and right-click in Explorer and select "Open Command Window Here" (at least in Win 7 and 8).
- Too 13y agoOr even faster: shift + context menu button, then W.
- deleted 13y ago[deleted]
- CrazedGeek 13y agoAbout the same speed on Windows 8: File -> Open Command Prompt.
- skrebbel 13y agoYep, this works fine, until you did it a 7th time and end up with a task bar full of unused console windows.
- BinRoo 13y agoI use CDargs http://www.skamphausen.de/cgi-bin/ska/CDargs http://www.skamphausen.de/cgi-bin/ska/CDargs
- mariusmg 13y agoI use powershell aliases for this. Works great.
- nawitus 13y agoCaps insensitive auto-complete is pretty handy. Add 'set completion-ignore-case on' to '/etc/inputrc'.
- gosukiwi 13y agoWatching all the comments, I think the author should create a repo so people can fork or contribute instead of comment different versions :p
- daGrevis 13y agoThis is great, but I don't see why this is better than autojump. * Autojump automatically saves marks, ~~~ cd Downloads # And you are done. ~~~ * You don't have to think about mark names, ~~~ cd Projects/Python # It will be called `python`. ~~~ * You don't need to remember mark names, ~~~ j haskell # If you want `Projects/Haskell`, odds are the mark is auto-named `haskell`. ~~~ * You can specify only some part of mark name; ~~~ j bar # And you are in `Stuff/foobar`. ~~~ Other than that, this is, as I said before, great! Looking forward to go through the source code to learn more about Bash.
- hadem 13y agoWhy on Earth would you want to save every directory you change to?!
- jonknee 13y agoI noticed that 'mark' doesn't work if you have spaces in a directory name which you can't avoid on the Mac (I tried to mark an interior folder inside the iPhone Simulator which is inside "~/Library/Application Support/iPhone Simulator/". Wrapping in quotes seems to do the trick: function mark { mkdir -p $MARKPATH; ln -s "$(pwd)" $MARKPATH/$1 }
- kelvie 13y agoI just do this (in zsh): setopt autopushd pushdminus pushdsilent pushdtohome pushdignoredups Which automatically pushes (unique) directories I've visted into $dirstack. Then I have an alias: d () { local dir select dir in $dirstack echo $dir break done test "x$dir" != x && cd $dir } That gives me a list of directories to jump to in my history: ~/src/git/emacs-prelude $ d 1) /home/kelvie/tmp/typhoon 3) /home/kelvie/src/git 2) /home/kelvie/tmp 4) /home/kelvie ?# So I just type 1-4 to go back to a directory I've previously been in.
- nXqd 13y agohappy guaranteed https://github.com/clvv/fasd https://github.com/clvv/fasd
- wvh 13y agoNice idea, reminds me of ncd from a far away, foggy past. I suggest some escaping on the directory name parameter though. If you're not careful, you're going to run into trouble with paths that have spaces or risk some nasty security issues with embedded special characters.
- georgecalm 13y agoHere's a `fish 2` shell version, that works on the Mac. You can add it as `~/.config/fish/functions/mark.fish`: set MARKPATH $HOME/.marks function jump cd $MARKPATH/$argv; or echo "No such mark: $argv" end function mark mkdir -p $MARKPATH; and ln -s (pwd) $MARKPATH/$argv end function unmark rm -i $MARKPATH/$argv end function marks ls -l $MARKPATH | cut -d' ' -f12-; and echo end
- TeMPOraL 13y ago-f9- for me in cut, but otherwise it works :). Thanks!
- jeroenjanssens 13y agoThank you all for your kind words and helpful suggestions! I shall adapt both the post and the code accordingly. Jeroen
- jeroenjanssens 13y agoI have just added (1) quotes to the code, (2) a section about tab completion, and (3) a note for Mac OS X users. Many thanks again; HN is a great community! Jeroen
- ChuckMcM 13y agoThis is how I know I am old I create a symlinks in my home directory to oft used locations and get there with cd ~/linkname Has the added bonus of making my short path be ~/linkname rather than ~/some/very/deep/pocket/in/some/git/repo
- bakul 13y agoI've been using the following in some form for over 3 decades! (now in zsh) alias .=cd In /bin/sh "." sources a script. While this can be common in a script, one rarely does this interactively so I usurped . for the most common operation! alias ,=pushd alias ,,=popd alias ,.=dirs Think of cd as a goto, pushd as a call, popd as a return and dirs as a stack trace! ..() { cd ../$* } cdpath=(. .. ~/src ~) Use of cdpath can be confusing so it is best to show part of $PWD in the prompt: PS1="%* %5. %h%(#.#.:) " This ends the prompt with a # if you are running as superuser. These aliases/functions are enabled in .zshrc (only if run interactively -- that is, they are included below the following test): if [[ ! -o interactive ]] ; then return; fi The "benefit" of Jeroen's mark/unmark is that these paths persist (and can be used from any window running a shell. I have not found much need for that + I can have different $dirs in different windows. Also, given that my shell windows (under screen) persist for a very long time, I don't need symlink's persistence! Alternatively I define "." to be a function that does arg specific operation (cd if a dir, acroread if .pdf, vi if text etc.).
- trentmick 13y agohttp://code.google.com/p/go-tool/wiki/GettingStarted http://code.google.com/p/go-tool/wiki/GettingStarted Works on all OSes.
- srinivasanv 13y agoI've been looking for a way to make this less annoying, hanks!
- skriticos2 13y ago"Like many others, I spend most of my day behind a computer." I tend to spend my time in front of one. Is there an advantage to being behind it? But jokes aside, I added this to my bashrc, looks useful.
- ttomaino 13y agoThis is a very informative thread for people trying to streamline their daily shell experience. I'm looking forward to experimenting with the utilities mentioned here. I spend a significant amount of time in, and moving between CVS sandboxes. All my sandboxes have the same internal directory structure, but the root of the path changes. To speed up navigation time I created a tool to replace directory names with aliases. The aliases are persistent. They can also be "stacked", which allows you to specify a sandbox as an alias, then reuse your existing aliases to navigate within the sandbox. Auto-completion in the shell is an excellent companion as well. More information on "stacked.aliases", as well as the source can be found here: https://github.com/ttomaino/stacked_aliases/wiki https://github.com/ttomaino/stacked_aliases/wiki. I include one example to illustrate: As an example, the following two sandboxes contain the Broadcom Ethernet driver: /build/username/sandbox_a/software/vendors/linux/linux-2.6.35.7/drivers/ethernet/broadcom /build/username/sandbox_b/software/vendors/linux/linux-2.6.35.7/drivers/ethernet/broadcom Use the add alias command aa <alias name> <directory> to create aliases for the sandboxes: aa a /build/username/sandbox_a aa b /build/username/sandbox_b Then create an alias for the Broadcom directory: aa brcm software/vendors/linux/linux-2.6.35.7/drivers/ethernet/broadcom To change to the Broadcom directory in sandbox_a, just stack the appropriate aliases using the ua command. Stacking is done by stringing the aliases together with a period delimiter: ua a.brcm To change to the Broadcom directory in sandbox_b: ua b.brcm
- lucaspiller 13y agoI have no idea if anyone else does this, but I use tmux a lot for different projects. I usually have vim in one tab, logs in another, and tests in another. However, each tab I open I need to cd into the same directory. As such I came up with this helper for zsh. Every time I change a directory it records it. When I start a new session (new tmux or iTerm tab) it goes straight to that directory: # record directory in ~/.lastpwd record_pwd() { pwd > ~/.lastpwd } chpwd_functions=(record_pwd) # go to last directory when opening a new shell if [[ -d `cat ~/.lastpwd` ]]; then cd `cat ~/.lastpwd` fi For other shells that don't have something like chpwd_functions you could just alias cd.
- phinze 13y ago> However, each tab I open I need to cd into the same directory. As of tmux 1.7, this should be unnecessary. Every tab and split will open in the working directory of the current pane, and the behavior can be changed with the `default-path` option.
- lamby 13y agoI've been doing a very similar thing for a few years: https://chris-lamb.co.uk/posts/optimising-directory-navigation-multiple-terminals https://chris-lamb.co.uk/posts/optimising-directory-navigati...
- hifi 13y agoGreat idea! I don’t want symlinks to be resolved (/var/www becomes /private/var/www on os x) so I modified it to store the path in the file: export MARKPATH=$HOME/.marks function jump { mark=$(head -n 1 "$MARKPATH/$1" 2>/dev/null) if [[ $mark != '' ]]; then cd $mark else echo "No such mark: $1" fi } function mark { mkdir -p "$MARKPATH"; echo "$(pwd)" > "$MARKPATH/$1" } function unmark { rm -i "$MARKPATH/$1" } function marks { find "$MARKPATH" -type f | while read filename do printf "%-12s -> %s\n" $(basename ${filename}) $(head -n 1 ${filename}) done } I think the if syntax is zsh so probably won’t work with bash.
- kodango 13y agoI've add a new bash version based on Jeroen's code, it's more easier to use in a Bash environment. Welcome to use, thanks for Jeroen's smart work. https://github.com/dangoakachan/mark-directory https://github.com/dangoakachan/mark-directory
- parski 13y agoI used some of this code to implement a more orthodox utility using flags instead of different syntax for different commands. https://github.com/parski/Wormhole https://github.com/parski/Wormhole It works great! Great blog post.
- kodango 13y agowhen mark name contains space, the auto complete doesn't work, anyone have solutions?
- dueyfinster 13y agoI've updated the completion code to work on ubuntu and os x: http://neil.grogan.ie/2013/08/quickly-navigate.html http://neil.grogan.ie/2013/08/quickly-navigate.html
- X4 13y agoMy Z-Shell predicts and auto-completes everything I do often perfectly, thus typing 2-3chars not only get's me deep into directories, but also do actions I need. But maybe the idea of folder bookmarks can still be useful, idk.
- m-r-r 13y agoI don't understand the advantage of using handwritten function instead of the shell builtins. The `mark` function could be replaced by `alias -g`, `jump` could be replaced by `cd` and `unmark` could be replaced by `unalias` : % cd ~/Dev/W3/m-r-r.github.io % alias -g :blog="$PWD" % jekyll build -d /tmp/out/ && cd /tmp/out % ./index.html % cd :blog % pwd /home/m-r-r/Dev/W3/m-r-r.github.io % alias -g :blog='/home/m-r-r/Dev/W3/m-r-r.github.io' :dev='/home/m-r-r/Dev' :c='/home/m-r-r/Dev/C' :python='/home/m-r-r/Dev/Python' :vim='/home/m-r-r/.vim' In addition, this method works with any shell command: % pwd /tmp/out % make -C :blog publish % git clone git://git.complang.org/ragel.git `echo :c`/ragel % vim `echo :vim`/templates/\*.rl On the other side, the aliases are not saved at exit unless you write a function to do it: % tail -n 15 ~/.zshrc function aliases { ( alias -L -r alias -L -g alias -L -s ) | uniq } function save-aliases { aliases > ~/.zsh_aliases } if [ -f ~/.zsh_aliases ]; then . ~/.zsh_aliases fi