News for hackers. Stuff that matters.
Re:Eza: A modern, maintained replacement for ls by alabhyajindal on Monday July 22, 2024 @04:44AM (#41032114)
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.
Re:Eza: A modern, maintained replacement for ls by networked on Monday July 22, 2024 @06:31AM (#41032834)
Nice 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
Re:Eza: A modern, maintained replacement for ls by blooalien on Monday July 22, 2024 @07:26AM (#41033182)
Ooo! Thank you! That is a nice tip! Stealing it right now. :)
Re:Eza: A modern, maintained replacement for ls by macintux on Monday July 22, 2024 @08:24AM (#41033596)
Seems like that would strongly encourage me to keep my directories tidier.
Re:Eza: A modern, maintained replacement for ls by creshal on Monday July 22, 2024 @09:16AM (#41034011)
It 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.

Re:Eza: A modern, maintained replacement for ls by bbarnett on Monday July 22, 2024 @10:20AM (#41034721)
So it's OK to hide the mess, by throwing everything from the living room into the closet, I guess?

Not to mention, in the old days, that stuff was modtly in dot files.

(Users install graphical file manager. User has file manager set to bizarrely show dotfiles by default. User gets mad at prior hidden "clutter". Now dotfiles hidden one dir down.)

Re:Eza: A modern, maintained replacement for ls by wadim on Monday July 22, 2024 @10:47AM (#41035057)
> So it's OK to hide the mess, by throwing everything from the living room into the closet, I guess?

Yes? This is literally how every human in the world does it. You put your things, according to catrgories, into their respective room/cabinet. If somebody asks you where your sweaters are, you don't say "just search the ground", you say " in the closet".

Same thing here. You don't have to guess where files are, you know by convention.

Re:Eza: A modern, maintained replacement for ls by bbarnett on Monday July 22, 2024 @10:53AM (#41035134)
My counterpoint was merely that ~/.<programname> hid things, unless you did weird things. Like explicitly ask to see all hidden things.

Having a file manager set to see all dotfiles by default, is like ripping all the doors off your closets.

Re:Eza: A modern, maintained replacement for ls by xelamonster on Monday July 22, 2024 @11:22AM (#41035496)
I don't think it's all that weird, it's one of the first things I'd do in any file manager and I make sure Windows Explorer shows me system files too. If never had to interact with the hidden config it would be one thing, but I very often do and I don't want extra friction in getting to them.
Re:Eza: A modern, maintained replacement for ls by creshal on Monday July 22, 2024 @12:03PM (#41035966)
You're completely missing the point.

~/.programname is an unorganized mess, where someone stuff their dirty laundry, their trash, their food and their passport into the same closet. It doesn't matter if the closet is open or not, nobody but the mentally ill hoarder who created the mess can navigate it.

~/.(local|share|cache) means people put their food in the fridge, their trash into the bin and their sensitive documents in a fire proof safe. Which means other people can take care of basic tasks like taking out the trash and creating backups of their sensitive documents.

Re:Eza: A modern, maintained replacement for ls by chippiewill on Monday July 22, 2024 @12:24PM (#41036223)
The one thing I despise about local|share|config is I never know which one they're using or what kind of nested hierarchy they're using that means I might have to search for the company name first.

At least with the ~/.whatever system I can just start typing ~/.tool-name, hit tab and it'll show me the thing if it exists. If it's somewhere else I have to look it up.

Re:Eza: A modern, maintained replacement for ls by creshal on Monday July 22, 2024 @12:44PM (#41036489)
It's not like ~/.whatever has ever been used consistently:

- ~/.mozilla/firefox, but: ~/.thunderbird and ~/.pki/nssdb (gonna keep you on your toes!)

- Java defaults to .full.package.name (on top of using .java, .openjfx, and others)

- Fontconfig uses `fc-*` for its tools. Naturally, its config file used to be in ~/.fonts.conf.d before they finally accepted standard directories

- arandr, as the name implies, uses .screenlayout

- The sooner the .net ecosystem decides if it wants to use ~/.dotnet or ~/.mono, the better (humble suggestion: ~/..net)

Re:Eza: A modern, maintained replacement for ls by account42 on Tuesday July 23, 2024 @10:28AM (#41046335)
> The one thing I despise about local|share|config is I never know which one they're using or what kind of nested hierarchy they're using that means I might have to search for the company name first.

This really only applies to badly ported Windows software like Unity engine games. There should be no hierarchy, just ~/.{local/share,config,etc.}/$application And nothing stops badly behaved software from deciding to use ~/.$CompanyName or heck I have even seen ~/My\ Documents/$CompanyName

Re:Eza: A modern, maintained replacement for ls by bbarnett on Monday July 22, 2024 @02:31PM (#41037954)
But that's disorganized!

I have a real filing cabinet. In it, I have folders.

I don't keep my backup car dongle in one folder, my car invoice in another, my warranty and info from dealer all in different folders. They're all in a folder with the car name on it.

The same for my fridge. The invoice, the manual, the warranty info, all in one folder.

It is much more disorganized to have a folder for manuals and put them all there. I have to find the one I want out of 50 such manuals. And if it is a warranty thing, then I need the invoice, and other papers.

Why would I want to keep associated things in different folders?!

You think it's a mess, but really it's not. It's organized for humans to find related things.

Before, I'd uninstall a program and delete its single dotdir. Done.

Now I have to hunt in a maze of madness to "get it all".

You cite some programs that didn't properly keep their data in a single dotdir, and use that as a reason why a single dotdir was bad?!

Re:Eza: A modern, maintained replacement for ls by creshal on Monday July 22, 2024 @05:13PM (#41039883)
> You cite some programs that didn't properly keep their data in a single dotdir, and use that as a reason why a single dotdir was bad?!

No. It's literally the other way around. It's bad that they keep everything in a single dotdir, because now I have to poke through dozens of folders to see where they hide their caches and other bloated garbage that shouldn't be backed up or kept in git, and where between all that garbage they're hiding their config files.

If all caches go to ~/.cache, I can exclude them all with a single setting, and I can put all my configurations in git/backups by adding ~/.config.

Same as with /var/tmp vs /etc vs /var/lib; if I want everything thrown together into a single folder I can just go use Windows.

Re:Eza: A modern, maintained replacement for ls by Too on Monday July 22, 2024 @02:40PM (#41038098)
~/.(local|share|whatever) means I have to search both the basement, the attic and the garage. For stuff i rarely need to touch so I forget every time where it was placed.

If it was only one place it would be great. If it was truly separated by config vs cache it would be great. The reality know though is that you have at least three locations where important config are stored, not counting those from package managers that have their own idea of this concept. Still, this mess is preferable to the even worse mess of hundred plumbing files spread on the living room floor.

Re:Eza: A modern, maintained replacement for ls by NetOpWibby on Monday July 22, 2024 @11:07AM (#41035325)
Unsettling concept tbh
Re:Eza: A modern, maintained replacement for ls by samatman on Monday July 22, 2024 @12:25PM (#41036238)
Taking this opportunity to remind folks: if you're going to emit a config file from your program, check for $XDG_CONFIG_HOME and use what you find by preference. ~/.config is a decent fallback. Sticking it in ~? It's not the 1980s anymore, please, don't.
Re:Eza: A modern, maintained replacement for ls by creshal on Monday July 22, 2024 @05:15PM (#41039906)
Config files are the lesser problem, although it's really, really, really useful for programs to realize that $XDG_CONFIG_HOME exists.

More importantly, please put your caches under $XDG_CACHE_HOME so they don't trash up my backups or git.

And if you're feeling really fancy, put all your runtime stuff in a separate dir in $XDG_RUNTIME_DIR so /tmp doesn't look like someone detonated a zip bomb in there. I want to use it for my temporary files and still find them, thank you very much.

Re:Eza: A modern, maintained replacement for ls by enriquto on Monday July 22, 2024 @03:36PM (#41038862)
> 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

Re:Eza: A modern, maintained replacement for ls by ktm5j on Monday July 22, 2024 @08:38AM (#41033697)
Oh cool idea! But gosh I think I would hate that.. I typically know what files are in directories that I'm working in, and usually care more about the output of previous commands I've run. I feel like this would teach me to never change directories
Re:Eza: A modern, maintained replacement for ls by idunnoman1222 on Monday July 22, 2024 @01:29PM (#41037007)
Also good practice
Re:Eza: A modern, maintained replacement for ls by xk3 on Thursday July 25, 2024 @11:06AM (#41069550)
When I want to cd I usually don't type cd. I use zoxide which is a modern autojump.

In fish shell you can also just type the directory path and press enter and it will change the working directory.

Re:Eza: A modern, maintained replacement for ls by diggan on Monday July 22, 2024 @12:24PM (#41036225)
Neat idea, thanks! So obvious in hindsight... Just need to add some logic to it so it doesn't output more than N files.

For others (like me) who use zsh:

    function chpwd() {
      ls
    }
Re:Eza: A modern, maintained replacement for ls by tutipop on Monday July 22, 2024 @01:07PM (#41036728)
I do the same in bash, but it's a bit wordier:

  _chpwd_hook() {
    if [[ "$PWD" != "$PREVPWD" ]]; then
      ls
      PREVPWD="$PWD"
    fi
  }

  PROMPT_COMMAND=(_chpwd_hook)
Goes well with

  shopt -s autocd
  alias r='cd -'
Re:Eza: A modern, maintained replacement for ls by mbivert on Monday July 22, 2024 @02:07PM (#41037542)
Not strictly equivalent, but shorter (and should work with multiple shells):

  $ cd() { builtin cd $* && ls; }
  $ cd /
  bin  boot cdrom  dev  etc  home  lib  lib64 [...]
Re:Eza: A modern, maintained replacement for ls by oxygen_crisis on Monday July 22, 2024 @04:14PM (#41039307)
$* will break on directory names containing spaces and other bash "word" delimiters, use "$@":

    cd() { builtin cd "$@" && ls; }
Re:Eza: A modern, maintained replacement for ls by fastasucan on Wednesday July 24, 2024 @12:00PM (#41058391)
A word of a warning if you have folders with _a lot_ of files.
Re:Eza: A modern, maintained replacement for ls by hggh on Monday July 22, 2024 @06:12AM (#41032697)
> 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-...

Re:Eza: A modern, maintained replacement for ls by nolist_policy on Monday July 22, 2024 @06:24AM (#41032777)
I just use bash and tab tab all the time.
Re:Eza: A modern, maintained replacement for ls by FergusArgyll on Monday July 22, 2024 @09:52AM (#41034372)
Yes! one full hand of mine is kept in reserve to keep hitting tab
Re:Eza: A modern, maintained replacement for ls by 000ooo000 on Monday July 22, 2024 @05:56AM (#41032585)
Bash 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).
Re:Eza: A modern, maintained replacement for ls by jmholla on Monday July 22, 2024 @12:25PM (#41036233)
Neat. Can you share the source of any of the functions you've bound to some of your keys?
Re:Eza: A modern, maintained replacement for ls by 000ooo000 on Saturday July 27, 2024 @08:46AM (#41086226)
Apologies 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.

Re:Eza: A modern, maintained replacement for ls by jiehong on Monday July 22, 2024 @05:33AM (#41032444)
I cannot find this shortcut in https://fishshell.com/docs/current/interactive.html.

Do you know where it's documented by any chance?

Re:Eza: A modern, maintained replacement for ls by ognyankulev on Monday July 22, 2024 @05:44AM (#41032507)
It'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."
Re:Eza: A modern, maintained replacement for ls by jiehong on Monday July 22, 2024 @07:09AM (#41033061)
Ah, it was an L, I thought it was an I (eye). Thanks
Re:Eza: A modern, maintained replacement for ls by tormeh on Monday July 22, 2024 @05:25AM (#41032384)
Also many shells come with greatly improved ls implementations built in, like that of nushell.
Re:Eza: A modern, maintained replacement for ls by fsiefken on Monday July 22, 2024 @06:04AM (#41032648)
yes, 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
Re:Eza: A modern, maintained replacement for ls by oneshtein on Monday July 22, 2024 @09:18AM (#41034036)
I just use mc and ctrl-O, to switch between shell and listing.
Re:Eza: A modern, maintained replacement for ls by nine_k on Monday July 22, 2024 @09:43AM (#41034287)
For 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.)

Re:Eza: A modern, maintained replacement for ls by whartung on Monday July 22, 2024 @12:12PM (#41036088)
To 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.

Re:Eza: A modern, maintained replacement for ls by jmholla on Monday July 22, 2024 @12:29PM (#41036294)
I 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`.

Re:Eza: A modern, maintained replacement for ls by zokier on Monday July 22, 2024 @01:43PM (#41037189)

    find -type f -printf '%M@ %p\0' | sort -zn | tail -z | sed -z 's/^[0-9.]* //' | ...
Ugh.. so unixy
Re:Eza: A modern, maintained replacement for ls by Macha on Monday July 22, 2024 @10:02AM (#41034487)
This appears to run eza for me, probably because I've aliased ls to eza. So I'm guessing it's just running `ls`.
Re:Eza: A modern, maintained replacement for ls by samatman on Monday July 22, 2024 @11:34AM (#41035620)
TIL! great tip, thanks. Now I just need to wire that shortcut up to `lsd` instead of `ls`.
Re:Eza: A modern, maintained replacement for ls by latchkey on Monday July 22, 2024 @12:23PM (#41036208)
history? atuin has been great.
Re:Eza: A modern, maintained replacement for ls by sva_ on Monday July 22, 2024 @01:42PM (#41037165)
In bash/zsh you can easily setup fzf completions ctrl-r (for directory) and ctrl-t (for shell history)
Re:Eza: A modern, maintained replacement for ls by mixmastamyk on Monday July 22, 2024 @04:47PM (#41039640)
I 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
Re:Eza: A modern, maintained replacement for ls by Osiris on Monday July 22, 2024 @10:37PM (#41042002)
I have been using fish for a long time and I didn't know about this. Thanks.