I have a utility called ZSH Autosuggestions, and it's probably one of the most useful things on my computer. It shows you a sort of preview of the most recent command you typed that matches the prefix of the current command you are typing. It's basically an automatic tool that bookmarks commands based on usage. I think the best bookmark systems are ones which simply track your entire history and suggest relevant pages based on it. That way the process of bookmark creation is automatic and you don't have to predict what you will need to access frequently.
This is essentially a fish built-in. I used to use zsh before, but since changing to fish I've never looked back.
Auto completion, abbreviations, better syntax, and especially the auto complete is like magic. It also seems to "know" in which working directories some commands work and won't suggest them if they arent.
I have to concur, fish is simply an amazing shell for interactive sessions. I've been using it for so long, I just take some things for granted, like the incredible autocomplete. As far as I understand, it looks at paths in history entries and won't suggest them if those aren't valid in the current directory. Then you also have the "shadow suggestion" described by GP, the Alt+arrows to just complete part of a history entry, the really good Ctrl+s (which also works for commands that implement fish suggestions, not just history), and so on.
I saw this in fish first. I really did want to love fish. I do love their tagline. However they are weirdly against comfigurable options and there were some minor things that irritated me that could not be configured away. So I looked at what zsh can do. I have a minimal setup now where I know what almost everything does and am very very happy with. Autosuggestions is fantastic.
I really wanted to like fish but it is so difficult to get it configured the way I would want to use it. I tried so many different ways and the barriers were just so high. It should not be so difficult to make a tool work the way I wanted to work.
> It also seems to "know" in which working directories some commands work
The 'It' above is actually the user as auto-complete is context dependent, so fish prioritises search results based on commands that were previously used within the current directory.
Seems like as good a time as any to show off this cursed thing I keep in my dotfiles:
# Allow .. through ........... (yup!) to cd up some number of directories.
for i in {1..10}; do
spaces=$(printf "%${i}s")
alias "${spaces// /.}."="cd ${spaces// /../}"
done
Going into it, I thought it would be something I'd use all the time. In practice all I ever use is `..` and not nearly as much as I originally imagined I would.
I have something similar (though less elegant). I find the best use case to be hitting ..........<RET> to get to root (in conjunction with zsh auto_cd option), rather than typing `cd /`.
alias .='dot_func'
alias ..='cd ../..'
alias ...='cd ../../..'
alias ....='cd ../../../..'
alias .....='cd ../../../../..'
dot_func ()
{
if [ $# -eq 0 ]; then
cd ..
else
source "$@"
fi
}
Interesting approach. Since I've converted entirely to nushell, I'm using zoxide to solve this navigation friction. https://github.com/ajeetdsouza/zoxide
The only thing I'm missing from zsh is path aware auto completion... supposedly this works if you enable the sqlite history for nushell but iirc it was buggy.
I never used pushd and popd. Did not even know about them. But I use autojump it give directories a prioroty numbers and then you just have to type "j pro" and you cd into your projects folder for example.
+1 for autojump since it's already in debian & ubuntu package repositories. Install with `apt install autojump` and add a line to your shell config file to load it. For Bash that means adding e.g. `source /usr/share/autojump/autojump.sh` to your .bashrc. Also works with zsh, fish, tcsh, clink.
pushd/popd are over 40 years old btw. Used to use them in the 90s. I decided invisible states requiring working memory create a cognitive split encouraging user error because you have to maintain the focus of the task and the invisible parts of the tool you're using to do the task.
Well ok, Jef Raskin decided that and I happen to agree with him.
My extension is "anything that requires traversing either taxonomies or invisible geometries is too much to ask." So for instance, tmux splits previous-pane and previous-window into two things so the "last thing I was looking at" now asks you to consider whether that was in a pane or a window[1] ... as if you had taken the time to diligently organize it (traversing taxonomy). Xorg's split of the clipboard into CLIPBOARD, PRIMARY, SECONDARY, CUT_BUFFER0-9 and every program having a different opinion on how to copy and paste into them is another one. And then tools like tmux have their own and tools like vim and emacs have their own. So vim, inside of tmux, inside of ssh, inside of some terminal ... right. [2]
Similarly, the multi-dimensionality of many tiled window managers (where you have up, down, left, right, tab left, tab right, workspace (up/down/left/right) etc ...) is like navigating via hypercube.
It's way too complicated to keep a mental model of and leads to lots of errors. I still use one because there's no other reasonable way to leverage the multi-tasking abilities of modern machines but it leads a lot to be desired. My user error rate is probably over 80%.
I'm sure some geniuses can do it but most people cannot.
[1] I have a fix!
Add this to .tmux.conf
set -g focus-events on
bind-key l run-shell "$HOME/bin/tmux-last switch"
set-hook -g pane-focus-out "run-shell 'tmux set-option @out #{pane_id}"
set-hook -g pane-focus-in "run-shell '$HOME/bin/tmux-last in #{pane_id} #{@out}"
It's still strait jacket drooling insanity, but at least it's a little less.
Probably the actual fix in X would be to somehow route all clipboards through DBus so then the user AND the application can have their own opinions and not have to have a bunch of accommodations for each other.
I made this helper function to navigate my projects, recursively, it will list them if there are more than one, but defaults to the first one unless you give it a number.
syntax:
projects <project-name> <match index>
alias:
function projects() {
if [ -z "$1" ]; then
echo "please provide a project name"
return
fi
local allMatches=$(find ~/Documents/projects -maxdepth 2 -type d -name "*$1*" -print)
local firstMatch=$(echo "$allMatches" | head -n ${2:-1} | tail -n 1)
if [ -z "$firstMatch" ]; then
echo "no matches found"
return
else
if [ $(echo "$allMatches" | wc -l) -gt 1 ]; then
echo "matches found:"
echo "$allMatches" | awk '{print NR ") " $0}'
fi
cd "$firstMatch"
fi
}
I really like "jump" which I have aliased to "j". It auto learns and you can also pin shortcut names so I don't have to fuss configuring it but also can control certain ones. Great trade off between usability and configurability. Can't find the repo but "brew install jump" works :)
An alternative is to use CDPATH [0], and possibly a directory containing symlinks as bookmarks. That way you can also switch between different sets of bookmarks by changing CDPATH. Add some shell aliases for managing that setup.
You can use `ranger` to interactively navigate to and select a directory:
cdranger() {
local tmpfile="$(mktemp)"
local cdto
ranger --show-only-dirs --choosedir="$tmpfile" "$@"
cdto="$(cat $tmpfile)"
rm -f "$tmpfile"
if [ "$cdto" ]; then
cd "$cdto"
fi
}
It’s kind of funny (in a good way) how there’s already been about 10 other ways mentioned in the comments! We do seem to love our directory navigation tools :)
This is certainly a viable alternative to requiring a project-specific environment variable. The downside is it can only succeed if $PWD is within the local git repo.
If this is the preferred approach, however, an alternative zsh definition for devhome could be:
devhome () {
cd $(git rev-parse --show-toplevel) && cd ./${~1}(/)
}
Would also be nice to be able create bookmarks to regularly used commands as part of the "Shunpo package". That way one wouldn't need to use another tool for these type of cases. Thoughts?
I end up using $CDPATH a lot for initial movement. While it's probably not as comprehensive as this, I find it and something like zoxide can cover a lot of ground.
I have a utility called ZSH Autosuggestions, and it's probably one of the most useful things on my computer. It shows you a sort of preview of the most recent command you typed that matches the prefix of the current command you are typing. It's basically an automatic tool that bookmarks commands based on usage. I think the best bookmark systems are ones which simply track your entire history and suggest relevant pages based on it. That way the process of bookmark creation is automatic and you don't have to predict what you will need to access frequently.
https://github.com/zsh-users/zsh-autosuggestions?tab=readme-...
This is essentially a fish built-in. I used to use zsh before, but since changing to fish I've never looked back.
Auto completion, abbreviations, better syntax, and especially the auto complete is like magic. It also seems to "know" in which working directories some commands work and won't suggest them if they arent.
I have to concur, fish is simply an amazing shell for interactive sessions. I've been using it for so long, I just take some things for granted, like the incredible autocomplete. As far as I understand, it looks at paths in history entries and won't suggest them if those aren't valid in the current directory. Then you also have the "shadow suggestion" described by GP, the Alt+arrows to just complete part of a history entry, the really good Ctrl+s (which also works for commands that implement fish suggestions, not just history), and so on.
Extremely useful on a daily basis.
I saw this in fish first. I really did want to love fish. I do love their tagline. However they are weirdly against comfigurable options and there were some minor things that irritated me that could not be configured away. So I looked at what zsh can do. I have a minimal setup now where I know what almost everything does and am very very happy with. Autosuggestions is fantastic.
This is also a `bash` (or rather any `readline` app) builtin.
Type any prefix, press `<esc>k` (or `<up>` in emacs mode) and it'll prefix match on history. Keep pressing `k` for older matches.I don’t even have to type anything in fish. It automatically shows prefix completions.
Fish really is amazing and it really is worth the minor transition costs.
I really wanted to like fish but it is so difficult to get it configured the way I would want to use it. I tried so many different ways and the barriers were just so high. It should not be so difficult to make a tool work the way I wanted to work.
So I too went back to zsh.
Agreed, zsh autocompletions are noticeably worse than fish and is precisely why when I switched to fish it was over
> It also seems to "know" in which working directories some commands work
The 'It' above is actually the user as auto-complete is context dependent, so fish prioritises search results based on commands that were previously used within the current directory.
Seems like as good a time as any to show off this cursed thing I keep in my dotfiles:
Going into it, I thought it would be something I'd use all the time. In practice all I ever use is `..` and not nearly as much as I originally imagined I would.I have something similar (though less elegant). I find the best use case to be hitting ..........<RET> to get to root (in conjunction with zsh auto_cd option), rather than typing `cd /`.
I use something similar: .. , .2 , .3 , etc.
I guess I'll share what I built for myself.
https://gist.github.com/chanux/1119556 (bash) https://gist.github.com/chanux/9411092 (fish)
That's `za <n>` to go back n directories up. It's a decade old and I still use this everyday.
I experimented with jumping up directory path by name with `xs`. But I don't use it that often (at all).
https://gist.github.com/chanux/08c6f53472190a02b33bd49100163...
I have the following in my .bashrc:
It’s usually enough. :)I had an alias ... for years and noticed I never really used it.
`cd ..` coupled with `cd ~` seems to be good enough, really.
Interesting approach. Since I've converted entirely to nushell, I'm using zoxide to solve this navigation friction. https://github.com/ajeetdsouza/zoxide
The only thing I'm missing from zsh is path aware auto completion... supposedly this works if you enable the sqlite history for nushell but iirc it was buggy.
Just a note that zoxide isn't specific to nushell in any way: I use it with great satisfaction in both zsh and bash!
I’ve used “bashmarks” for this for years: https://github.com/huyng/bashmarks
Super handy. This looks like it might be more polished version.
I never used pushd and popd. Did not even know about them. But I use autojump it give directories a prioroty numbers and then you just have to type "j pro" and you cd into your projects folder for example.
https://github.com/wting/autojump
just looked at it again it also has a jc command for child directories and commands to open file explorer that I never used.
+1 for autojump since it's already in debian & ubuntu package repositories. Install with `apt install autojump` and add a line to your shell config file to load it. For Bash that means adding e.g. `source /usr/share/autojump/autojump.sh` to your .bashrc. Also works with zsh, fish, tcsh, clink.
pushd/popd are over 40 years old btw. Used to use them in the 90s. I decided invisible states requiring working memory create a cognitive split encouraging user error because you have to maintain the focus of the task and the invisible parts of the tool you're using to do the task.
Well ok, Jef Raskin decided that and I happen to agree with him.
My extension is "anything that requires traversing either taxonomies or invisible geometries is too much to ask." So for instance, tmux splits previous-pane and previous-window into two things so the "last thing I was looking at" now asks you to consider whether that was in a pane or a window[1] ... as if you had taken the time to diligently organize it (traversing taxonomy). Xorg's split of the clipboard into CLIPBOARD, PRIMARY, SECONDARY, CUT_BUFFER0-9 and every program having a different opinion on how to copy and paste into them is another one. And then tools like tmux have their own and tools like vim and emacs have their own. So vim, inside of tmux, inside of ssh, inside of some terminal ... right. [2]
Similarly, the multi-dimensionality of many tiled window managers (where you have up, down, left, right, tab left, tab right, workspace (up/down/left/right) etc ...) is like navigating via hypercube.
It's way too complicated to keep a mental model of and leads to lots of errors. I still use one because there's no other reasonable way to leverage the multi-tasking abilities of modern machines but it leads a lot to be desired. My user error rate is probably over 80%.
I'm sure some geniuses can do it but most people cannot.
[1] I have a fix!
Add this to .tmux.conf
Where tmux-last is https://9ol.es/tmp/tmux-last[2] If you are a traditionalist using xterm or some derivative, this block taken from my .Xresources should be enlightening
It's still strait jacket drooling insanity, but at least it's a little less.Probably the actual fix in X would be to somehow route all clipboards through DBus so then the user AND the application can have their own opinions and not have to have a bunch of accommodations for each other.
I made this helper function to navigate my projects, recursively, it will list them if there are more than one, but defaults to the first one unless you give it a number.
syntax:
alias:I really like "jump" which I have aliased to "j". It auto learns and you can also pin shortcut names so I don't have to fuss configuring it but also can control certain ones. Great trade off between usability and configurability. Can't find the repo but "brew install jump" works :)
<https://github.com/gsamokovarov/jump>
Personally, I've been using z (<https://github.com/rupa/z>) for ages and never really needed more.
Yes, z, and for interactive navigation the `simple directory navigator` sdn [1] - together with `ls` that's all I need.
[1] https://git.janouch.name/p/sdn
Agreed! „z“ and atuin (https://github.com/atuinsh/atuin) cover most of my needs.
An alternative is to use CDPATH [0], and possibly a directory containing symlinks as bookmarks. That way you can also switch between different sets of bookmarks by changing CDPATH. Add some shell aliases for managing that setup.
[0] https://www.gnu.org/software/bash/manual/html_node/Variable-...
You can use `ranger` to interactively navigate to and select a directory:
Jump around! https://github.com/rupa/z
Nice. While I prefer a combination of these tools
Small helpers are always good to have. Thanks for sharingI use Yazi with all of those - it also has ripgrep integrated
Between all of those it's hard to think of a better experience navigating a filesystem.
I also use
along with kitty. Unfortunately I did not find an (acceptable) way to simulate the behaviour of GNOME extension with kitty or alacritty. A dropdown Terminal with image protocol for file preview would be very cool.It’s kind of funny (in a good way) how there’s already been about 10 other ways mentioned in the comments! We do seem to love our directory navigation tools :)
I use an Array + Sed to go backwards in path to an exact directory without having to spam cd ..:
https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9...
A project-specific zsh[0] function I find quite handy is:
This assumes an environment variable DEV_HOME is assigned to be the location of the top-level directory for a given project. An example of its use is: 0 - https://www.zsh.org/i mostly use this to go from inside a repo up to the root:
This is certainly a viable alternative to requiring a project-specific environment variable. The downside is it can only succeed if $PWD is within the local git repo.
If this is the preferred approach, however, an alternative zsh definition for devhome could be:
Looks great, thanks!
Would also be nice to be able create bookmarks to regularly used commands as part of the "Shunpo package". That way one wouldn't need to use another tool for these type of cases. Thoughts?
I use https://github.com/jarun/nnn/ with `cd` on quit if I need to scan around manually. Otherwise, zoxide.
I've been pretty happy with Ranger (https://github.com/ranger/ranger)
I end up using $CDPATH a lot for initial movement. While it's probably not as comprehensive as this, I find it and something like zoxide can cover a lot of ground.
In DOS I used to something like this, using ctrl or alt and an f key to set or go to a bookmarked directory.
Love the Bleach reference in the name.
cdbuff: Your Grandpa's cd Command https://github.com/akoerner/cdbuff
oh man, i had no idea stuff like this (or pushd/popd existed). i’ve been writing so much ugly bash to do this myself… whoops
Emacs + projectile + eshell
There's a glaring issue with this... one of its commands conflicts with the absolutely crucial system administration tool `sl`. :-)
[dead]