7 ms·
* 'set -o vi' in bash lets me search my command history with the same keys as moving around vi * git + sql scripts * simplenote (notes across devices) Semi-a
by mooreds 10y ago
* 'set -o vi' in bash lets me search my command history with the same keys as moving around vi
* git + sql scripts
* simplenote (notes across devices) Semi-automation of pieces of my job captured in these notes.
* zapier if I'm trying to connect two web apis.
- vram22 10y agoIn bash: $_ in a command gets substituted by the last argument of the last command you typed - happens to be useful surprisingly often. Simple example: copy a file to some other directory, then cd or pushd to that directory: $ cp some_file /long/path/to/directory # cd $_ But there are many other cases where I regularly find it useful. _ also evaluates to result of the last expression in the Python interactive shell, and probably in IPython (command-line version) as well - need to confirm it about IPython. Edited for formatting of commands above.
- tyrylu 10y agoNot the original poster, but the _ trick works in ipython as well.
- vram22 10y agoCool, thanks for confirming.
- ryandrake 10y agoAnother useful bash thing: !! (which substitutes the last command you entered) cat /really/long/path/to/something/only/readable/by/root cat: Permission denied (goddamnit) sudo !!
- vram22 10y agoYes, that's a good one :) There are zillions more such that can be done in Unix, of course, if one puts one's mind to it and experiments, even without spending a lot of time. Another simple one I use some is to define some environment variables to the value of long directory names to which I need to go often as part of some project. Then I can just do: cd $short_name_for_that_dir A shell alias can also be used instead.
- blacksmith_tb 10y agoOh yeah, I sudo bang-bang all the time (it's in other shells, too, zsh for example). I am also fond of !$, which is the object of your last command - lots of times I will ls a file to see the timestamp or confirm it's there; and then want to open it / edit it / rm it, which just looks like $ ls /long/path/to/file.ext $ less !$
- waterhouse 10y agoWhat if you need to run a third version of the command, or a version that involves deletions, e.g. "less /really/long/path/to/..."? bash-3.2$ less /var/log/authd.log.0.gz "/var/log/authd.log.0.gz" may be a binary file. See it anyway? bash-3.2$ I type: control-P control-A meta-D zcat control-E | SPACE less bash-3.2$ zcat /var/log/authd.log.0.gz | less On the OS X terminal, you have to configure it to treat option as meta before the meta-D above will work. I forget whether common Linux terminals require such configuration. (Edit: zless would work just as well here, and on Linux "less" appears to basically have the functionality of zless.)
- mwpmaybe 10y agoWith set -o vi: <ESC> k cw zcat <ESC> A <SPACE> | <SPACE> less <CR> Very natural for any Vi user: go up a "line", change the first word, then append.
- deathanatos 10y agoAnother one I love is that both bash & zsh can edit the current command in $EDITOR. In bash, it's ^X^E by default, and in zsh, I think you have to bind it. (it's edit-command-line, which I strangely can't find in man zshzle.)
- billbrown 10y agoInstead of $_ you may find ESC+. easier. I have.
- vram22 10y agoCool, didn't know of that one.
- zulln 10y agoI would love to have a self-hosted version of Zapier. I am not really comfortable with a third party having that much access to all my web services. However, all their supported services together with a few lines of Python is really powerful.
- vram22 10y ago>'set -o vi' in bash lets me search my command history with the same keys as moving around vi +10 I love 'set -o vi' and have been using it for ages, since ksh in fact. It makes editing commands and then re-issuing them so fast in Unix, if you're even just okay at vi - don't even need to know vim. Used to immediately put it into the .kshrc on any new Unix system I started working on (along with some other commonly used productivity settings, of course). A fact that some might not know about 'set -o vi' is that once it is set (a one-time task per login shell, or put it in your login shell's profile file, then it is one-time, period), and you are now editing a command at the command prompt (using vi features), you can just press v to open up vi with a temp file containing that command, edit it using the full-screen view and power of vi, then save the file and it runs automatically. This is particularly useful for multi-line shell commands like a for or while loop, or a long command pipeline. And while in that vi session, if you decide you do not want to run the command right now, you can always save it to a different, persistent file name (with :w filename), and exit the temp file without saving it. Then the command will not run, but you've saved it in a permanent file, and can do anything with it, now or later.This is useful if you realize in the middle of editing it, that you want to look up some command syntax (to add to the file), or polish the code some, etc., but maybe not right now, because you want to finish your current task first (which the original command sequence was a part of). You can just edit that permanent file at your leisure later, polish and test it, then use it regularly as needed. Edited for formatting and grammar.
- oskarth 10y ago> you can just press v to open up vi with a temp file containing that command, edit it using the full-screen view and power of vi, then save the file and it runs automatically. FWIW you can do this with ctrl-x ctrl-e in normal (emacs-like mode) and it will open up your $EDITOR. Example: > EDITOR=nano # or EDITOR=vi, EDITOR=emacs, etc > echo [ctrl-x ctrl-e] * edit command by adding foo and save* > echo foo
- allannienhuis 10y agoawesome tip! thanks!