by blockloop on 1/14/17, 8:21 PM with 180 comments
by Normal_gaussian on 1/14/17, 9:09 PM
For example
:!ls
will execute ls and show you the result (press enter to return) :r!ls
will read the result of ls in for youMore usefully
:r!sed -n5,10p that/other/file
will read lines 5-10 from that other file.However you will most often want to
:!make
:!up build
:!git status
:!git commit -am "Fixed #23"
by greenspot on 1/15/17, 12:25 PM
Ctrl-r search history
- then Ctrl-r again to show next match
- then Tab to show all options
Ctrl-p previous command or arrow up
Ctrl-n next command or arrow down
export HISTCONTROL=ignoreboth:erasedups
Add to .bashrc to avoid duplicate entries
Ctrl-a to beginning of line
Ctrl-e to end of line
Alt-b one word back
Alt-f one word forward
Ctrl-k delete to end of line
Ctrl-u delete to beginning of line
Alt-d delete to end of word
Ctrl-w delete to beginning of word
Alt-Backspc same
cd - change to last dir
pushd <dir> mark current dir and go to <dir>
popd go to marked dir
z fuzzy cd, install from https://github.com/rupa/z
j fuzzy cd and more, install via autojump
Ctrl-z to background & suspend
bg recent background app continue running
fg bring recent background app to front
disown -h remove recent background app from current tty
fg %n bring nth app to front, e.g.: fg %2 for second
less better than cat, doesn't flood screen, same keys
find find files, e.g. find / -name <filename>
ag install via the_silver_searcher, faster grep
tree shows dir like a GUI app, install
!! last command, e.g. sudo !!
fish bash alternative with more sensible defaults
man bash read more about bash
by oblio on 1/14/17, 9:33 PM
> I know there are some cool newcomers out there like zsh and fish, but after trying others out I always found that some of my utilities were missing or ill-replaced.
First of all bash was first released in 1989 and zsh arrived just 1 year later so zsh is in no way a newcomer.
Secondly zsh is almost strictly a bash superset so I don't know what he was missing (or what he found "ill-replaced").
by teddyh on 1/14/17, 9:40 PM
1. Ancient.
2. Will most likely never be updated by Apple
(Most GNU- and Linux-based systems, and also Windows, on the other hand, continue to use the latest versions.)
by whack on 1/14/17, 10:11 PM
if [ -t 1 ]
then
# search for commands that start off with the same characters already typed
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
fi
One of my friends also recommended version-controlling your config files and storing them on gitlab, which I'm only sad I didn't do sooner. It's been such a help in keeping my aliases and configs in sync, as I make changes across numerous different machines.by h2hn on 1/15/17, 12:13 AM
Substring history search, so you can use just a substring to look for a argument,command. Binded to ctr+r/s by default. ;)
https://github.com/liloman/asyncBash#use
Changing directories: Last n directories, transparent popd/pushd.
https://github.com/liloman/dirStack
Movements: vim-surround for your cli, so you can do ysiw" o whatever... ;)
https://github.com/liloman/bash-surround
Control-n right: So just type the start and control+n to search for the arguments/commands starting with whatever. And the classical up/down to look up for a complete history line:
https://github.com/liloman/dotfiles/blob/master/bash/.inputr...
https://github.com/liloman/dotfiles/blob/master/bash/.inputr...
There're a ton of hidden functionality and customization behind the classical bash instalation. :)
by wyclif on 1/15/17, 1:22 AM
While there is much useful in this post, I always find comments like this one odd. bash was released back in 1989, zsh was released one year later, in 1990. One year difference in age almost thirty years ago means that you can't really call zsh a newcomer. Maybe he's talking about adoption, though.
by alphast0rm on 1/14/17, 9:20 PM
Tracks your most used directories, based on 'frecency'.
After a short learning phase, z will take you to the most 'frecent'
directory that matches ALL of the regexes given on the command line, in
order.
For example, z foo bar would match /foo/bar but not /bar/foo.
by TheAceOfHearts on 1/15/17, 7:57 AM
With fish I have a setup.fish script that defines all my universal exports, for when I setup a new computer. This is for private tokens, like HOMEBREW_GITHUB_API_TOKEN. For aliases and utilities, I wrote a fisherman [0] plugin. It has a functions folder and a fishfile for the few other plugins I use.
by why-el on 1/15/17, 2:44 AM
If you want to delete everything and don't want to keep typing yes just do `yes | rm bla`.
by lxe on 1/15/17, 3:57 AM
by xolb on 1/14/17, 11:31 PM
by alkonaut on 1/15/17, 9:50 AM
I'm not sure I agree with that. If you work in a decent IDE and your vcs is not git then you can do pretty well without a terminal. Especially on Windows.
by llasram on 1/15/17, 12:12 AM
by pmoriarty on 1/15/17, 12:19 AM
For me, as far as shells go it's usually enough to know the basics and be able to look stuff up when debugging other people's shell scripts.
by johnchristopher on 1/15/17, 12:11 PM
by gigatexal on 1/14/17, 11:38 PM
by gogolb on 1/14/17, 10:35 PM
ip addr show en0 | grep -inet\ | awk '{ print $3 }' | awk -F/ '{print $1}' | pbcopy
you can use: ipconfig getifaddr en0
If you wanna stick with ip addr, a more compact command is: ip addr show en0 | awk '/inet/{split($2,a,"/"); print a[1]}'
by Scea91 on 1/15/17, 4:53 PM
by hiq on 1/15/17, 12:14 AM
LESS=+/"DEFAULT KEY BINDINGS" man readline
assuming it exists on mac.
About suspend, what's the benefit of suspending vim using C-z? Shouldn't you use a terminal multiplexer instead, or even terminal tabs if you don't want to learn how to use tmux or screen (which I find weird if you already spent time to learn how to use vim but alright)?
I only ever suspend a program when I want it to stop, for instance because it slows other programs and I realize I would rather resume it when I'm not in front of my computer. Even in that case, I often just renice the program instead. Stopping a program just because you want to run some bash commands looks like an anti-pattern to me, but maybe there are better motives I'm not aware of.
by danielrm26 on 1/15/17, 2:50 AM
bindkey -v bindkey -M viins 'jk' vi-cmd-mode
Then you can edit your command line the same way you would edit a line in vim.
by blunte on 1/15/17, 10:55 AM
Notably they don't work in MS Office, but they work in web browsers and practically every other app I have on my Mac.
by santaclaus on 1/14/17, 10:34 PM
by coldtea on 1/15/17, 2:31 PM
Sounds like the author never heard of Windows development.
by Graziano_M on 1/20/17, 8:52 PM
What? No. Use Ctrl-f and Ctrl-b. I use this probably more than any other readline shortcut.
Ctrl-h for backspace, Ctrl-d for delete. Half my keyboards don't even have arrow keys and I don't miss them.
by teddyh on 1/14/17, 9:29 PM
He means “ctrl-w”. But since that only works in bash, not in Emacs or other tools with Emacs key bindings, it makes more sense to use (in his terminology) “alt-backspace”. This does the same thing, and works both in the shell and in Emacs-like environments.
by nurb on 1/15/17, 9:29 AM
sudo !!
In the same way, "!*" is all the arguments of your previous command, and "!$" only the last one.by RJIb8RBYxzAMX9u on 1/15/17, 6:36 AM
by wodenokoto on 1/14/17, 10:00 PM
by ivanhoe on 1/15/17, 4:06 PM
Also there's a big difference between Alt + Backspc and Ctrl + w. The first will delete a word consisting of only alphanumerics, while Ctrl + w also deletes the word, but word can be made of any characters other than space.
by mr_donk on 1/15/17, 6:45 AM
Don't ctrl-f and ctrl-b work?
by rofrol on 1/18/17, 6:25 PM
by ndesaulniers on 1/15/17, 5:26 AM
by annetee on 1/15/17, 10:15 PM
Alt-l converts next word to lowercase
Alt-u converts next work to uppercase
by thiagof on 1/15/17, 8:05 PM
by cel1ne on 1/15/17, 11:37 AM
Option + Cursor-Left/Cursor-Right to jump words
by rerx on 1/23/17, 10:02 AM
by philonoist on 1/15/17, 6:03 AM
by greenspot on 1/15/17, 9:56 AM
ctrl-r search in history, ctrl-r again to skip-
ctrl-p previous command (instead of arrow up)
ctri-n
by lisivka on 1/14/17, 9:37 PM
mc allows to explore system efficiently while not standing in my way, because I can always press ctrl-O and get my shell back.
bash-completion saves time on typing of commands.
Other tools I install often are htop (better ps) and strace.
by krzyk on 1/14/17, 10:36 PM
by SFJulie on 1/14/17, 11:59 PM