This was enabled by default in some distro, I think it was Mandrake Linux. I learned to use it and now I can't live without it. 's' is always ready to be immediately pressed, and it can even be spammed.
export EDITOR=vim
function highlight() {
egrep --color "$1|\$"
}
function mkcd() {
mkdir $1
cd $1
}
function git-cite() {
git log -1 $1 "--pretty=format:%H (\"%s\")%n" | sed -e 's/\([0-f]\{12\}\)[0-f]*/\1/'
}
alias gd='git diff'
alias gpr='git pull --rebase'
(and a bunch of other similar aliases)
function gcmr() {
git checkout origin/merge-requests/$1
}
C-r search history and recall (C-R for another match)
C-o run and recall next (C-O next, C-O next, ...)
C-M-/ undo last edit
M-d delete next word
M-backsp delete prev word
C-y paste text deleted by the two above (combined), Emacs's "yank"
M means Meta key, substitute Alt key on a PC.
Not really off-topic, these combos facilitate writing fabulous one-liners.
One super-useful key combo which is often overlooked is C-x-e, which edits the current command in $EDITOR. Very useful when dealing with history and long commands that need parameter editing.
For downloading a single page from a website for offline storage capabilities. A private, quick, and simple alternative to saving information using archive.org.
# go back to the last directory
cd -
# run last command with sudo
sudo !!
# truncate file
> /tmp/file-to-truncate.txt
# show directory size
du -sh my-dir
# refresh output of command every 2 seconds (needs watch command)
watch ls /tmp
# check how long a command takes
time du -sh mydir
Then I also have a neat function for cd ..:
function ..() {
for i in $(seq 1 $1); do cd ..; done
}
# cd ..
..
# cd ../../../../
.. 4
#!/bin/bash
# install in /usr/local/bin/nap
if [ -z $1 ]; then
echo "No time provided. Usage: nap [-cl] [minutes]"
exit 2
fi
if [[ $1 == *c ]]; then
echo Cancelling sleep. PIDs \(if any\): `pgrep -f "nap"`
pkill -f "nap"
exit 0
fi
if [[ $1 == *l ]]; then
ps -Af | grep nap
exit 0
fi
time=$(($1 * 60))
echo Sleeping in $1 minutes...
sleep $time && pmset sleepnow&
I wrote this 10+ years ago, still use it every day.
lets you edit with vi, all the files matching that grep pattern.
For example, this is useful for editing all files of a project, which contain a particular variable name, in order to change that name to something else everywhere it is used.
The single quotes in the command should actually be backward single quotes, which I don't have on my mobile keyboard right now.
I love this one and use it all the time, especially using the special case when your command can take multiple filename arguments and they come last. xargs will glom as many as it can into a single command before overflowing the max command line size, which can be faster than starting many processes. Grep is the best example: