Live data from Hacker News

Shell Productivity Tips and Tricks

blog.balthazar-rouberol.com

11–20 of 97 posts

Re: Shell Productivity Tips and Tricks

#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 alternative ways of passing secrets (using configuration files for example).

Re: Shell Productivity Tips and Tricks

#12
post #6

xargs should be there. The most useful tool IMO.

As zsh is mentioned at various points throughout the article I'll add that zargs¹ is often a great alternative to xargs. Combined with zsh's awesome globbing and filtering functionality it is often far nicer to work with than find.

1. https://github.com/zsh-users/zsh/blob/master/Functions/Misc/... or zshcontrib(1)

Re: Shell Productivity Tips and Tricks

#13
post #12
post #6

xargs should be there. The most useful tool IMO.

As zsh is mentioned at various points throughout the article I'll add that zargs¹ is often a great alternative to xargs. Combined with zsh's awesome globbing and filtering functionality it is often far nicer to work with than find. 1. https://github.com/zsh-users/zsh/blob/master/Functions/Misc/... or zshcontrib(1)

I think zsh is the best shell ever, unfortunately, I've reverted to bash, because it's too much hassle to install zsh everywhere I work. zsh globbing is on another level.

Re: Shell Productivity Tips and Tricks

#14
post #13
post #12

Earlier quoted context omitted.

As zsh is mentioned at various points throughout the article I'll add that zargs¹ is often a great alternative to xargs. Combined with zsh's awesome globbing and filtering functionality it is often far nicer to work with than find. 1. https://github.com/zsh-users/zsh/blob/master/Functions/Misc/... or zshcontrib(1)

I think zsh is the best shell ever, unfortunately, I've reverted to bash, because it's too much hassle to install zsh everywhere I work. zsh globbing is on another level.

> zsh globbing is on another level.

I agree. That said I'll freely admit that liberal use of glob modifiers and qualifiers can lead to the appearance of line noise. Because of that I'll occasionally unroll them with `find(1)`-syntax if I post a snippet to help a co-worker, but love their expressiveness when in an interactive session.

For people not familiar with the extensive globbing options of zsh see https://linux.die.net/man/1/zshexpn .

Re: Shell Productivity Tips and Tricks

#15
post #8

Whoever can point me at a robust method to save/restore bash histories of a tmux session would save my life!!! [And yes i use tmux inside tmux]

I use this to have all shells share a history concurrently - which sometimes is confusing if you press "↑" and have an unexpected (possibly dangerous command) but I'm used to it now:

  shopt -s histappend
  PROMPT_COMMAND="history -a; history -c; history -r"
See more about it here: https://unix.stackexchange.com/questions/1288/preserve-bash-...

Re: Shell Productivity Tips and Tricks

#17
post #8

Whoever can point me at a robust method to save/restore bash histories of a tmux session would save my life!!! [And yes i use tmux inside tmux]

About a year ago I went further into this rabbit hole and right now I think I am on a re-iteration of a system I have not changed in about 4 months. It came to me after watching too much sci-fi that had clicky-clicky-typie-typie instant recall.

It occurred to me that every hack around history just nibbles at the edges probably because all of them are bolted on a design when the systems were slow. Systems now are fast and have good connectivity ( at least to themselves ) hence:

"All logins across all systems that have the same security domain share single common command history."

I use bash but it should be adoptable to anything. Here's how it works:

1. There's a database. I use redis because it is fast and has SETNX. [I may switch this to a redis queue to be able to archive commands as well.]

2. Using PROMPT_COMMAND variable I execute a function that pulls the last executed command using "history 1" and pushes it into the database. SETNX ensures that only a command that has not been seen before is stored. In the same transaction I trim the number of commands stored in the database to 5000.

3. Ctrl-R is bound to fetching last 5000 commands from the database, piping it into "peco" which I use with the selection line on a top ("fzf" does not support the top line so I don't use it here. "peco" does not support certain header skips/treatments, so i use "fzf" in other places )

4. On a failure to push into the database, system does nothing as the data is in a local history.

5. On a failure to pull from the database, system feeds the result of the local history into the "peco".

This system gives me ability to access the same command line history across my laptops, workstation, VMs, random Linux devices that i have running at home. Our ops-team uses it across all the monitoring workstations

Re: Shell Productivity Tips and Tricks

#18
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…

How exactly?

Re: Shell Productivity Tips and Tricks

#20
post #3

fzf fizzy history search with ctrl-r is my favorite new shell trick. Fzf is a wonderful program

I too prefer fizzy history. It's like Sodastream for your shell!

Skim [0] is a nice alternative to fzf [1], mainly for the fact you can call additional commands dynamically like so [2]:

    sk --ansi -i -c 'rg --color=always --line-number "{}"'
[0] https://github.com/lotabout/skim [1] https://github.com/lotabout/skim#difference-to-fzf [2] https://github.com/lotabout/skim#interactive-mode
Post reply on HN