Live data from Hacker News

Shell Productivity Tips and Tricks

blog.balthazar-rouberol.com

81–90 of 97 posts

Re: Shell Productivity Tips and Tricks

#81

  **
is not "expanded to all files and directories in the children directories, with a depth limit of 1." It's hard to see using `ls` because `ls` doesn't just list its arguments, it also lists files inside its directory arguments. Use

  echo **
and you'll see it just expands to the same as

  *
- all the files in the current directory. Or type

  **
and press Ctrl-x, Ctrl-* (glob-expand-word) to expand it.

After `shopt -s globstar`

  **
expands to all files recursively.

Also, `echo $dir | tr '[:lower:]' '[:upper:]'` should be `printf '%s' "$dir" | tr '[:lower:]' '[:upper:]'` to handle spaces and other weirdness in file names.

(If anyone knows how to escape asterisks in HN it would be helpful to know :)

Re: Shell Productivity Tips and Tricks

#82
post #11

> If you want to remove a sensitive command from your history, you can simply edit your $HISTFILE history file and remove it. It’s already too late at this point. Anybody on your machine can read the commands you are running, for example with ps. You should instinctively avoid entering anything in plaintext into a terminal which you don’t want other people to see. Any command line tool worth its salt will provide alt…

This doesn't have to be true. You can mount /proc with hidepid to prevent users from seeing other users' processes: https://access.redhat.com/documentation/en-us/red_hat_enterp...

Re: Shell Productivity Tips and Tricks

#84
post #43
post #35

fishshell is my favorite productivity enhancer for the terminal: https://fishshell.com/ The primary reason I chose over zsh/bash was that autocompletion just works. If you install it, I highly recommend oh-my-fish as well, which allows you to add packages for look/functionality: https://github.com/oh-my-fish/oh-my-fish If you're a zsh user, they have a similar framework: oh-my-zsh: https://github.com/ohmyzsh/ohmyzsh

I really enjoyed using fish for a short while, but soon I learned that it was not POSIX compliant. This was a deal breaker for me since my colleagues would often share scripts that wouldn't just work for me. I use zsh nowadays.

Well, you could always just use a shebang or call bash/sh directly on the file.

Re: Shell Productivity Tips and Tricks

#85
post #76

Earlier quoted context omitted.

Have you checked out Warp drive for zsh? https://github.com/mfaerevaag/wd It is more manual than z, but takes out the learning phase. Will check out z though!

It depends on how you work, I have a lot of small projects which come and go, so setting up the paths every time I start or finish something would be inefficient. Although I might adopt it for different weird system configuration directories which I often forget the path to.

Yes I have had that problem already, more specifically cleaning the lists in wd if directories are moved or removed. I do a cronjob to try to rectify that but interested to see if z mitigates this problem - seems there is an option -x to remove learned directories.

[edit] Or z's based ageing ranking system will just aged those legacy directories, even better (in terms of more hands off)!

Re: Shell Productivity Tips and Tricks

#87
post #42

I rarely use Ctrl+r to get command from history, because most of the time I know the starting characters of the command I need. So, I type those characters and use arrows keys to match from history. This is enabled via these settings in .inputrc # use up and down arrow to match search history based on typed starting text "\e[A": history-search-backward "\e[B": history-search-forward I also changed couple of setting w…

You can use ctrl+r for commands which are similar (say ssh to n number of servers, so the up/down would still take some amount of browsing the options) Just tag commands with a # at the end > $ complex command here # tagHere Later use the tag with ctrl+r I do this all the time > ssh 127.0.0.1 # master

yep, ctrl+r is better suited for such cases or whenever you have to match a command other than starting characters

and I think there are some fuzzy matching options (like fzf) that can be added to ctrl+r

Re: Shell Productivity Tips and Tricks

#88
post #42

I rarely use Ctrl+r to get command from history, because most of the time I know the starting characters of the command I need. So, I type those characters and use arrows keys to match from history. This is enabled via these settings in .inputrc # use up and down arrow to match search history based on typed starting text "\e[A": history-search-backward "\e[B": history-search-forward I also changed couple of setting w…

When I used bash, I had all of your settings on (had more, some others I can live without - these four I can't). I still have them in .inputrc for programs that use readline!

I have since switched to zsh. Up/down to search history, in ~/.zshrc:

    [[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" history-beginning-search-backward                                              
    [[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" history-beginning-search-forward
Autocompletion in zsh is a different beast altogether :)

Re: Shell Productivity Tips and Tricks

#89
post #45
post #43

Earlier quoted context omitted.

I really enjoyed using fish for a short while, but soon I learned that it was not POSIX compliant. This was a deal breaker for me since my colleagues would often share scripts that wouldn't just work for me. I use zsh nowadays.

I love zsh, but it isn't without its own strange quirks that make compatibility exciting at times. In a thread from a fortnight ago¹, RANDOM is handled very differently for example. Try `echo $(echo $RANDOM) $(echo $RANDOM)` in zsh and bash. I'm unsure whether minor differences that catch you out occasionally are worse than huge differences that you always have to think about. For me zsh still wins ;) 1. https://news…

Wow! Even repeating that call always yields the same result in zsh - as long as it's a subshell.

I think your comment will save my sorry ass one day.

Re: Shell Productivity Tips and Tricks

#90
post #72

Some plugins that saved me lots of typing with zsh: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/histo... looks through your history and only shows entries that started with the same characters that you already typed. Similar to Ctrl-R with fzf, but still similar enough that I use both. https://github.com/zsh-users/zsh-autosuggestions also looks through your history for commands with the same start, but it…

I'm a huge fan of the first 2 plugins, but I didn't know about the per-directory history plugin. I might put that in my toolbox. Thanks for the recommendation!
Post reply on HN