1. create aliases for everything in ~/.bashrc to speed things up
2. window stacking / multi-tasking in iTerm with cmd + (shift) + d
3. turn on vi(m) syntax highlighting by adding :syntax on to ~/.vimrc
4. use jq to format and colorize json files / streams with the pipe | operator (so useful!)
5. Generate a custom command prompt at http://bashrcgenerator.com/ (just for fun)
I really like this topic, so made a video going into more detail on mine, if anyone's interested https://youtu.be/okGN2RXFw_U
Imagine you write something like this:
# moutn -o ro -o remount /dev/hda0 /
Arg! I should have written mount, not moutn!
Easy fix:
# ^moutn^mount
I find it better than editing the last line (with cursor). It even works at boot and without 'doskey-like' arrow history.
vim: use :!some_shell_command --with_arguments to run a shell command from within vim quickly
also :set hlsearch to allow search highlighting, and use :noh to disable the current highlight once you no longer need the text to be a different color
tmux: Prefix-[ to scroll up console text. use / to search down, and ? to search up (just like in vim)
tmux: Prefix-z to zoom current pane to full size of window
zsh: vi-mode plugin to quickly use vim shortcuts on terminal input text, history-substring-search plugin to quickly remember what finicky command I was using earlier
also shells in general: ctrl-s to pause text (eg if you want to pause log spam), ctrl-q to resume
ssh -XC for compressed x11 forwarding, to speed up x11 responsiveness
on remote server: python2 -m SimpleHTTPServer 8080 --bind localhost to quickly start a simple file/http server from the current directory that is NOT internet accessible (ie nobody steals your shit)
then on local computer: ssh -L 8080:localhost:8080 to tunnel to remote server's localhost server. then just type in localhost:8080 in firefox to access remote server's files
vim: use :w !cmd to pipe the current buffer into a command but display the output from the cmd to screen and discard it afterwards
vim: use :r !cmd to read the output from the command and insert it into the current buffer
All of the :! and :r and :w commands that deal with a shell can also be passed the filename for the current buffer with %, eg:
":r !md5sum %" will execute md5sum with the filename of the current file (if it is unsaved, it will use the on-disk version, obviously) then pull the output checksum into the current buffer at the cursor position
ctrl+r (reverse search) on steroids: fzf (https://github.com/junegunn/fzf)
put a symlink to my dot files to a dropbox folder (always backed up .bash_profile or whatnot)
ssh tunnel to expose a port from a remote server on my computer: ssh -L 8500:localhost:8500 $remotehost
expose a port on my machine to the internet (demos and such): https://ngrok.com/
git bash prompt and git completion: know at a glance the branch I'm on and if there is un-staged/un-committed code. Allow tab complete for remotes and branch names. Lots of options here.
autojump (https://github.com/wting/autojump): `j foo` will jump directories to my /whatever/foo directory. Better than popd and pushd.
And before I had it baked into my prompt: `echo $?` to show the exit code of my last command.
add a "# tags" at any commands end to use above for future.
so lets say you have a ssh into multiple servers
$ ssh -Uasfd host1 # server1
$ ssh -Uaiouhqe host2 # server2
then later, ctrl+r -> and type ver1
$ mv file.text !#:1:r.txt
evaluates to:
$ mv file.text file.txt
(colon separated)
!# means this command
1 is the position of the argument to be modified
r means strip extension
There's tons of history modifiers and a lot to be learned reading `man bash`.2. autojump
3. solarized theme
4. zsh and antigen(particularly https://github.com/desyncr/auto-ls and https://github.com/psprint/zsh-navigation-tools)
$ rm file
> denied
$ fucking rm file $ rm file
> denied
$ fucking !!
Hmmm.Also in .vimrc I add: set noswapfile, set nobackup, and set nowb
These were probably useful when terminal sessions were conducted over flaky modem connections. I use Raspberry Pis a lot, so I'd rather not speed up the SSD card's inevitable failure.
I understand that you don’t want to further shorten the lifespan of your raspberry pi MicroSD card life, but maybe you should just buy better cards with a longer life?
Or maybe don’t work directly on the raspberry pi all the time, and only scp or rsync the files over there when you’re done developing stuff?
Do you make /tmp unwritable by all processes, too? What about /var/tmp?
Any other standard safety measures you always turn off that you want to share with us?
They are the terminal equivalent of iconising a window. You can do some form of multitasking without screen/tmux/byobu
ctrl-a to go to begining of line, ctrl-e to go to end of line, ctrl-u to delete line
oh-my-zsh to display nice contextual info on git, navigate more easily etc.
If you have commands you use regularly (unit test, building, git, etc.), keep a tab for each and create a profile so that it goes directly in the folder you need, and can have a different color.
esc-b to jump back a word on the terminal
esc-f to jump forward a word on the terminal
nerdcommenter (my favorite vim plugin)
git-gutter (my 2nd favorite vim plugin)
!-2 (repeats 2nd to last command)
I didn't know that command even exists. You can just use it in pipe with grep/sed/... to look for specific commands used in servers you do not directly manage often (Eg last time I used them I was looking for all the docker commands in a server to understand how to startup the correct containers and in which order)
set -o vi
- CMD + E to go to end of current line.
- `sudo !!` to run last command with `sudo`
Also, iirc the readine library cod also be switched to vin-like keybinding.
Also, a nice surprise thst i found in macOS is that come keybindings like C-a and C-e work in textboxes in macOS.
Useful to save the current directory, go somewhere else, do stuff and then come back to the original directory.
It works awesomely in bash scripts too!
printf "\033#8"