Live data from Hacker News

Shell Productivity Tips and Tricks

blog.balthazar-rouberol.com

31–40 of 97 posts

Re: Shell Productivity Tips and Tricks

#31
post #27

The single best shell productivity tip for me was to use z: https://github.com/rupa/z It automatically makes a list of directories you frequently use in your shell and if you type `z a-small-substring-of-the-directory-path` it does a cd to that directory. (e.g. I type `z and` and it changes my current directory to $HOME/Work/Projects/android`). Saved me tons of typing.

Agree, so useful! A port is also available for PowerShell: https://github.com/vincpa/z

Re: Shell Productivity Tips and Tricks

#32
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.

you may want to look at https://github.com/romkatv/zsh-bin. roman also has some tooling which helps when ssh-ing to remote servers without zsh.

Re: Shell Productivity Tips and Tricks

#33
post #29
post #27

The single best shell productivity tip for me was to use z: https://github.com/rupa/z It automatically makes a list of directories you frequently use in your shell and if you type `z a-small-substring-of-the-directory-path` it does a cd to that directory. (e.g. I type `z and` and it changes my current directory to $HOME/Work/Projects/android`). Saved me tons of typing.

A somewhat less fancy version of this is $CDPATH. export CDPATH="/path/to/my/projects:$HOME/Work/Projects" # From anywhere. cd andr

Note that CDPATH can break shell scripts that assume `cd` hasn't been adulterated.

A huge block of "unalias" calls at the beginning of shell scripts used to be a common practice, but they don't seem to be found in more widely-used tools these days.

Re: Shell Productivity Tips and Tricks

#34
> Toggle your cursor between its current position and the beginning of line

That's quite not what ^X^X does. The bash man page says:

Swap the point with the mark. The current cursor position is set to the saved position, and the old cursor position is saved as the mark.

Re: Shell Productivity Tips and Tricks

#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

Re: Shell Productivity Tips and Tricks

#36
The article links to this at the bottom, but just calling it out again because I think it's so useful. I am using git all the time---probably a majority of my terminal relates to git in some way. I think the git bash completion script is extremely useful. https://github.com/git/git/tree/master/contrib/completion

It's incredibly easy (and transparent) to "install" and saves a ton of keystrokes.

Re: Shell Productivity Tips and Tricks

#37
On more handy set of emacs-derived keystrokes:

Ctrl-a ctrl-k to clear the current command, or redo a hidden password prompt if you know you fat-fingered it.

ctrl-a jumps the cursor to the beginning of the line, and ctrl-k deletes from current position to the end of the line.

The mnemonic to remember these: "a" is the first position in the alphabet, and jumps you to the first position. "K" is short for "kill.”

Re: Shell Productivity Tips and Tricks

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

I understand what you're saying but if anybody on your machine can read the commands, can't they also read your configuration files? Or are you saying a different user on the machine can run `ps` and see my processes but not necessarily my portion of the file system? My thought is if the file is not encrypted on the disk, then any desktop application can read it. So, while I agree that preventing a user from reading bash history is not worth it if they can read your processes, aren't configuration files (if unencrypted) just as insecure?

Re: Shell Productivity Tips and Tricks

#39
post #29
post #27

The single best shell productivity tip for me was to use z: https://github.com/rupa/z It automatically makes a list of directories you frequently use in your shell and if you type `z a-small-substring-of-the-directory-path` it does a cd to that directory. (e.g. I type `z and` and it changes my current directory to $HOME/Work/Projects/android`). Saved me tons of typing.

A somewhat less fancy version of this is $CDPATH. export CDPATH="/path/to/my/projects:$HOME/Work/Projects" # From anywhere. cd andr

TIL, magnificient! It doesn't work on the minimal Centos 7, so you need:

    yum install -y bash-completion
    bash      # a fresh run

Re: Shell Productivity Tips and Tricks

#40

On more handy set of emacs-derived keystrokes: Ctrl-a ctrl-k to clear the current command, or redo a hidden password prompt if you know you fat-fingered it. ctrl-a jumps the cursor to the beginning of the line, and ctrl-k deletes from current position to the end of the line. The mnemonic to remember these: "a" is the first position in the alphabet, and jumps you to the first position. "K" is short for "kill.”

Ctrl-u (delete everything from the cursor to the beginning of line) is one less stroke for the very same result :)
Post reply on HN