Live data from Hacker News

Command line tools for productive programmers

earthly.dev

71–80 of 143 posts

Re: Command line tools for productive programmers

#71
post #8

For his usecase of funky i use ~/.bash_aliases, that way i can easily share them between machines. Eg to quickly add a new one: alias als="nvim $HOME/.bash_aliases && source $HOME/.bash_aliases" Be careful with quoting though, got myself into a situation where every new terminal asked for the root password. Shellcheck found the reason quickly. (edit) Another benefit is that those aliases abstract over differences of…

Instead of creating aliases for .., I use this: function ..() { for i in $(seq 1 $1); do cd ..; done } which enables .. # up 1 dir .. 2 # up 2 dirs .. 42 # up 42 dirs Here are some more: https://pilabor.com/blog/2021/03/unix-shell-tricks/

With Zsh, I am using:

    # Expand ... to ../..
    function vbe-expand-dot-to-parent-directory-path() {
      case $LBUFFER in
        (./..|* ./..) LBUFFER+='.' ;; # In Go: "go list ./..."
        (..|*[ /=]..) LBUFFER+='/..' ;;
        (*) LBUFFER+='.' ;;
      esac
    }
    zle -N vbe-expand-dot-to-parent-directory-path
    bindkey "." vbe-expand-dot-to-parent-directory-path
    bindkey -M isearch "." self-insert

Re: Command line tools for productive programmers

#72
post #19

Brains recently got underrated. The way mcfly works is cool, but it offloads your habits to some “neural network” that you can’t control. There is not many methods slower than looking at unpredictable line-by-line output and almost nothing more anxious than a possibility of false choice done without thinking. This tool basically replaces a deterministic mismatch with a non-deterministic one. Your brain is good at pre…

Author here, thanks for reading. I totally agree that non-determinism is tricky. The big thing that got me to try McFly was the suggestions are path specific. I hear fish shell has this feature built in, but I havn't tried it out.

I may be unique in this regard but the types of actions I do in one path are very different from those I do in others: working on my blog is very different from the types of things I do when working on code and it was nice to have history aware of this.

I haven't actually used McFly a lot though, so I haven't quite seen if it going to become a permanent thing for me. The UI of using FZF for history is nicer, I just didn't like the suggested matches.

You are right though, I don't have my arrow keys setup like this. I'll try that out as well. Thanks for the tip!

Re: Command line tools for productive programmers

#73

I would suggest https://rubygems.org/gems/ruby-each-line-2 e.g. ps -A | grep ruby | grep fsevent | ruby-each-line "puts l.split.first" | xargs kill -9 cat c | ruby-each-line "puts l.split.first[0..-2]" >> .env.development pbpaste | ruby-each-line "puts l.split.last" | ruby-all-lines "puts lines.map(&:strip).join(',')"

I don't want to be That Guy who says his way is best but I can only really see this being useful for someone who knows no shell tools at all.

> ps -A | grep ruby | grep fsevent | ruby-each-line "puts l.split.first" | xargs kill -9

  killall -9 -r ruby.\*fsevent
> cat c | ruby-each-line "puts l.split.first[0..-2]" >> .env.development

  awk '{ print(substr($1, 0, length($1) - 1)) }' c  >> .env.development
or

  awk '{ print $1 }' c | rev | cut -c2- | rev >> .env.development
> pbpaste | ruby-each-line "puts l.split.last" | ruby-all-lines "puts lines.map(&:strip).join(',')"

  pbpaste | awk '{ print $NF }' | paste -sd,
(I couldn't work out exactly what the last two did so I'm not sure my translation is accurate. Even if it's not quite right I doubt the intent would be impossible to express with basic tools.)

Re: Command line tools for productive programmers

#75

Earlier quoted context omitted.

Instead of creating aliases for .., I use this: function ..() { for i in $(seq 1 $1); do cd ..; done } which enables .. # up 1 dir .. 2 # up 2 dirs .. 42 # up 42 dirs Here are some more: https://pilabor.com/blog/2021/03/unix-shell-tricks/

This might be a better alternate to preserve functionality of `cd -` function ..() { cd $(printf '../%.0s' $(seq 1 $1)) }

Mmh, what do you mean with "preserve"...? `cd -` works like a charm for me.

Re: Command line tools for productive programmers

#76
post #71

Earlier quoted context omitted.

Instead of creating aliases for .., I use this: function ..() { for i in $(seq 1 $1); do cd ..; done } which enables .. # up 1 dir .. 2 # up 2 dirs .. 42 # up 42 dirs Here are some more: https://pilabor.com/blog/2021/03/unix-shell-tricks/

With Zsh, I am using: # Expand ... to ../.. function vbe-expand-dot-to-parent-directory-path() { case $LBUFFER in (./..|* ./..) LBUFFER+='.' ;; # In Go: "go list ./..." (..|*[ /=]..) LBUFFER+='/..' ;; (*) LBUFFER+='.' ;; esac } zle -N vbe-expand-dot-to-parent-directory-path bindkey "." vbe-expand-dot-to-parent-directory-path bindkey -M isearch "." self-insert

Wow, this is complex... but interesting, thank you :-) I use zsh, too.

Re: Command line tools for productive programmers

#77
post #58

> However, if the directory has many files or sub-directories, tree becomes much less helpful: you only see the last screen full of information as files scroll past you. tree | less

Recently i’ve taken to using nnn for anything like this: https://github.com/jarun/nnn - i never used cli file managers but now, it’s up there with my shell, vim & tmux as a core productivity tool. Show me files in this dir: $ n Show/hide details for each: . Filter / search file list: / Navigate subdirs (or parents) with vim or arrow keys. Cd into sub dirs by typing unique chars from dir names: ctrl-n Drop back to she…

If you’re already in vim, why not use whatever equivalent to NERDTree is popular? Unless you’re only interested in the structure and names, and not the file contents?

It seems like they even have a neovim plugin, you might consider using it.

Re: Command line tools for productive programmers

#79

Earlier quoted context omitted.

> this is the opposite of the unix way of doing things Which makes sense, this is an article for people on Apple hardware (judging by the installation instructions), so no interest in keeping things "the unix way of doing things"

I have no dog in this fight (I use both Linux and macOS as daily drivers) but it could be argued that macOS has more of a claim to be Unix than Linux since the foundation of macOS comes from NeXTSTEP and FreeBSD whose codebases both ultimately descend from the original Bell Labs Unix, whereas Linux started life completely independently. I'd argue that Linux is more Unixy than macOS in terms of philosophy though, I re…

OSx is also Unix certified by the open group, along with hp-ux and aix.

https://www.opengroup.org/openbrand/register/

Re: Command line tools for productive programmers

#80
post #9

> if the directory has many files or sub-directories, tree becomes much less helpful: you only see the last screen full of information as files scroll past you. > broot solves this problem by being aware of the size of your terminal window and adapting its output to fit it. What? You can just pipe `tree` into `less`. The solution isn't to download Yet Another Binary that does this specific thing and doesn't come inst…

I generally just use zsh globbing for this by the way:

  ls **(.)
To list all files, recursively, or some variation thereof depending what I want: *(/) for directories, *() for executable files, etc. With a global alias it can be piped to less with LL: "ls *(.) LL". You can actually do a lot of stuff with it, and is basically good replacement for find, except with less typing. The syntax looks a bit daunting at first, but especially for basic stuff it's not that hard (e.g. / and is the same as what ls -F uses).

I wish there was a better pager than less though, but haven't really found it (and no, Rust project X with 115 different colours that don't even work on a light background and/or "fuzzy" matching that never gives me what I want is not it).

Post reply on HN