6 ms·
My ls usage went down 100% after I switched to fish shell. The built in Alt + l command lists the directory contents. Very helpful! And also results in a cleane
by alabhyajindal 2y ago
My ls usage went down 100% after I switched to fish shell. The built in Alt + l command lists the directory contents. Very helpful! And also results in a cleaner shell history.
- mixmastamyk 2y agoI realized most of my ls runs come right after `cd`, so I added these to my startup files. Now almost every `cd` does `ls` automatically: # bash, simple function cd() { builtin cd "$@" && ls -l } # fish, a bit more sophisticated function cd builtin cd $argv; if test $status -gt 0 # there was an error, stop return end # auto print dir info if test "$argv" != "" # not home though dir # aka ls -l ... end end
- Osiris 2y agoI have been using fish for a long time and I didn't know about this. Thanks.
- tormeh 2y agoAlso many shells come with greatly improved ls implementations built in, like that of nushell.
- fsiefken 2y agoyes, but the good thing is that you don't have switch shells with this. I'm running nushell on windows, which is nice, but I haven't got it as concise with $env.config.table.mode = "none", it also doesn't feature the tree display
- jiehong 2y agoI cannot find this shortcut in https://fishshell.com/docs/current/interactive.html https://fishshell.com/docs/current/interactive.html. Do you know where it's documented by any chance?
- ognyankulev 2y agoIt's there, in Shared bindings: "Alt+L lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed."
- jiehong 2y agoAh, it was an L, I thought it was an I (eye). Thanks
- 000ooo000 2y agoBash users: FYI you can bind shortcuts like this, too. I have my right hand home row keys bound to __bash_ctrl_n() (for e.g.), and various tools in my dotfiles override these functions (git, if installed, sets up __bash_ctrl_e() to run git status and git log).
- jmholla 2y agoNeat. Can you share the source of any of the functions you've bound to some of your keys?
- 000ooo000 2y agoApologies for the slow response. They're not really interesting: - ctrl+j => equivalent of 'ls -la' using exa/eza - ctrl+k => git status followed by git log showing only current branch's commits (vs. tracked) - ctrl+l => sometimes I'll manually bind this to 'git reset @~' - ctrl+; => thinking I'll use this for calling fzf through my wrapper which sets up hotkeys for either `cd`/`$EDITOR`-ing the selected item Point is to reduce typing of the commonly-used commands. Somewhere in my shell profile/rc setup (I'm on Workman, not Qwerty, hence NEOK instead of JKL;): bash_functions=( "__bash_ctrl_n" "__bash_ctrl_e" "__bash_ctrl_o" "__bash_ctrl_k" ) for bash_function in "${bash_functions[@]}" do if ! type -t "$bash_function" 1> /dev/null then eval "$bash_function() { echo \"$bash_function(): This function should be overridden/aliased\"; }" fi done Then in my .bashrc (Note the leading space prior to `__bash_ctrl_x` - with Bash's `HISTCONTROL=ignorespace`, these keybinds won't pollute your history): bind '"\C-n": "\C-u __bash_ctrl_n\C-j"' bind '"\C-e": "\C-u __bash_ctrl_e\C-j"' bind '"\C-o": "\C-u __bash_ctrl_o\C-j"' bind '"\C-k": "\C-u __bash_ctrl_k\C-j"' Then in my app-specific configs/dotfiles: __bash_ctrl_n() { git status; git log ..; } Bonus: these Bash bindings can be cool for little QoL tricks, e.g. Ctrl+Y to rerun the last command with sudo. bind '"\e\C-y": "\C-usudo !! \C-j"' Other good ones: - Append `--help | $PAGER` and run - Rerun last command and pipe into $PAGER (some terminals support viewing last command output in a pager without re-running it, e.g. Kitty) Hope that helps.
- hggh 2y ago> And also results in a cleaner shell history In Bash you can also keep the history cleaner by adding ls (or other commands) to the HISTIGNORE env var: https://superuser.com/questions/232885/can-you-share-wisdom-on-using-histignore-in-bash https://superuser.com/questions/232885/can-you-share-wisdom-...
- nolist_policy 2y agoI just use bash and tab tab all the time.
- FergusArgyll 2y agoYes! one full hand of mine is kept in reserve to keep hitting tab
- networked 2y agoNice tip. What got rid of most of my use of `ls` in fish was running `ls` automatically when you changed directories: function ls_on_cd --on-variable PWD ls end
- fastasucan 2y agoA word of a warning if you have folders with _a lot_ of files.
- blooalien 2y agoOoo! Thank you! That is a nice tip! Stealing it right now. :)
- macintux 2y agoSeems like that would strongly encourage me to keep my directories tidier.
- creshal 2y agoIt absolutely did for me. Sadly, it also serves as constant reminder that ~ is a bloody mess because people still can't get used to .local/.share/.config.
- enriquto 2y ago> people still can't get used to .local/.share/.config I'm one of those people... I don't want yet more hidden stuff in my home dir; I want less. My dream is to have zero hidden directories in my home. What I want is something really clean like this: $ ls -a ~ . .. config fun local pro tmp This is almost possible, thanks to XDG_ environment variables. But unfortunately many programs still use hardcoded names for the local userdirs. If you want to get closer to that goal, the xdg-ninja [0] package can help you. Also, do something like "touch ~/.local ; chmod 000 ~/.local" to force programs that use hardcoded names to fail spectacularly (instead of recreating the hidden dir). [0] https://github.com/b3nj5m1n/xdg-ninja https://github.com/b3nj5m1n/xdg-ninja
- 2y ago
- oneshtein 2y agoI just use mc and ctrl-O, to switch between shell and listing.
- nine_k 2y agoFor me, there are two principal cases of sorting in `ls` output: alphabetical when I'm trying to find something I don't know/ remember exactly, and mtime-based when I want to see the latest (or oldest) in a group of related files. I don't see how it could work with one shortcut. Another thing is `ls -l` that's important when I need to understand file sizes and especially how symlinks are set up. Yet another is `ls -ld` which explains details about directories. All these cases could be made more ergonomic, and maybe partly merged. But I don't see how I could compress them into one type of output that fits all purposes. (My current fancy version of `ls` is `lsd`, but I still use the built-in `ls` a lot.)
- whartung 2y agoTo this end I made a simple script, `latest`, which is, essentially, `ls -lt $@ | head`. So, `latest *.log`, etc. Other than that, simple autocomplete does a lot of my ls work for me.
- jmholla 2y agoI know you're showing a rough example, but others might want to throw a `-d` in there so that folders don't get expanded. And put `$@` in quotations so spaced file names don't get interpreted as separate arguments. i.e.: ls -ltd "$@" | head edit: `-d` may be a bad choice. It also results in directories being listed first on my system, even with `-t` passed. edit 2: That was an alias I had setup. Carry on with the `-d`.
- zokier 2y agofind -type f -printf '%M@ %p\0' | sort -zn | tail -z | sed -z 's/^[0-9.]* //' | ... Ugh.. so unixy
- Macha 2y agoThis appears to run eza for me, probably because I've aliased ls to eza. So I'm guessing it's just running `ls`.
- samatman 2y agoTIL! great tip, thanks. Now I just need to wire that shortcut up to `lsd` instead of `ls`. Update: the ls command is stored at __fish_ls_command, so this is a `set -g __fish_ls_command lsd` in `config.fish`.
- latchkey 2y agohistory? atuin has been great.
- sva_ 2y agoIn bash/zsh you can easily setup fzf completions ctrl-r (for directory) and ctrl-t (for shell history)