Live data from Hacker News

Shell Productivity Tips and Tricks

blog.balthazar-rouberol.com

71–80 of 97 posts

Re: Shell Productivity Tips and Tricks

#71
post #67
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.

Sound similar to autojump. https://github.com/wting/autojump

The advantage of autojump - at least for me - is that it doesn't depend on the shell, as it is implemented in Python. This makes it possible to read and write the data elsewhere, too, independent of your shell.

For example, I integrated it into ranger (see my history, I don't want to spam HN with this project).

Re: Shell Productivity Tips and Tricks

#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 will automatically suggest them for you to use. If you often use the same commands, this saves quite some typing. For bonus points, I hooked it up so that Ctrl-Return will execute the suggestion.

https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/per-d... To make the first two even more powerful, I split my history based on the directory I'm in. This means that it's only suggesting me commands I entered before in this directory.

Re: Shell Productivity Tips and Tricks

#73
post #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 :)

Ctrl+U is also really handy for clearing password (or any other input) lines where you know you made a mistake, but don't want to just spam Backspace until you think you've gotten to the beginning.

Re: Shell Productivity Tips and Tricks

#74
post #54
post #38

Earlier quoted context omitted.

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…

In a Unix system, files have 3 levels of permissions — for the user who owns the file, the group-of-users that owns the file, and any system user. So, a given config file can have permissions so that the file owner can read and write, but other users cannot. Like your ssh keys. But ‘ps’ can be run by anyone, and it can typically access the whole command line you used.

This is true but in a typical desktop usecase there is one user.

Re: Shell Productivity Tips and Tricks

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

This is my workhorse, 'to'.

No argument: start fzf (this really should read "to $(fzf)"), jump to that dir.

One arg: if the path is a real file/dir, jump to it, else use zoxide (z in rust) to soft-match it from history.

https://github.com/xkortex/bashbox/blob/master/aliases/core....

Re: Shell Productivity Tips and Tricks

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

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.

Re: Shell Productivity Tips and Tricks

#77
post #57

Best shell productivity trick ever: don't use the shell for anything more complicated than launching executables and use a reasonably modern programming language to achieve all other tasks.

no thanks. 'rename .txt _1.txt *' is quite a few lines in a language that's super simple, like Python, and it turns into code golf with even more terse languages. I'll stick to the terminal.

> anything more complicated than launching executables

mv is a simple executable. GP is talking about stuff like generating reports or sophisticated orchestration in .sh

Re: Shell Productivity Tips and Tricks

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

> Anybody on your machine can read the commands you are running, for example with ps.

This is why I always mount /proc with the "hidepid=2" option (as well as the "gid=" option to ensure that doesn't apply to the members of a specific group, such as the "admins" of the box).

Re: Shell Productivity Tips and Tricks

#79
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]

Histdb is amazing, but requires zsh. I have one continuous history. I'm working on figuring out multi-host history for One True History.

https://github.com/larkery/zsh-histdb

I haven't tried it, but the keywords you are looking for is bash history db/sqlite. E.g.:

https://github.com/thenewwazoo/bash-history-sqlite/blob/mast...

Re: Shell Productivity Tips and Tricks

#80
My productivity stack:

Zsh (with all the autocomplete plugins)

Oh-my-zsh zsh-autosuggestions: https://github.com/zsh-users/zsh-autosuggestions

Tmux

Histdb: https://github.com/larkery/zsh-histdb

Zoxide (replace cd): https://github.com/ajeetdsouza/zoxide

Fzf

Rip (replace rm): https://github.com/nivekuil/rip

My personal dotfiles: https://github.com/xkortex/bashbox

Mosh (replaces/augments ssh)

What I'm currently looking for is a better multi-host logging solution.

Post reply on HN