What customizations have you done on your shell profile to increase productivity?
Solution 1
.vimrc
save file with root permissions by typing w!!
:
cmap w!! w !sudo tee % > /dev/null
.bashrc
Don't bother with devices or binary files whengrep
ing:
alias grep='grep --color=auto --binary-files=without-match --devices=skip'
Share code on the web (like pastebin, but simpler) by
cat 1337.sh | webshare
alias webshare='curl -F "sprunge=<-" http://sprunge.us | xclip'
It gives back a short url in your clipboard; you can append ?whatever-lang
to the returned URL to have it syntax highlighted and lines numbered.
.inputrc
Use vi mode in everything that uses the readline library (many programs):
set editing-mode vi
set keymap vi
Solution 2
make a directory and cd in one command
Most of the time I do mkdir
, my next command is cd <that dir>
.
This saves some typing:
# make a directory and cd to it
mcd()
{
test -d "$1" || mkdir "$1" && cd "$1"
}
for example:
/home/mikel$ mcd somedir
/home/mikel/somedir$
Another thing I find useful is an easy way to make a throwaway directory. e.g. if I'm compiling a program or even if I'm trying to reproduce a problem on this site. Sometimes I might forget to clean up the directory.
# make a temporary directory and cd to it
mtd()
{
local dir
dir=$(mktemp -d)
if test -n "$dir"
then
if test -d "$dir"
then
echo "$dir"
cd "$dir"
else
echo "mktemp directory $dir does not exist"
fi
else
echo "mktemp didn't work"
fi
}
showing it working:
/home/mikel$ mtd
/tmp/tmp.wsnZjJ2KN6
/tmp/tmp.wsnZjJ2KN6$
I am relying on the system cleaning up /tmp
after a reboot, but it would be possible to enhance this, e.g. make it delete the temp dir after exiting the shell.
Solution 3
I like to have my bash prompt show the exit code of the previous command if it was non-zero. I also like my shell to cheer me up when I use it, so I added a bit of silliness:
smiley() {
RC=$?
[[ ${RC} == 0 ]] && echo ':)' || echo ":( ${RC}"
}
export PS1="\$(smiley) \h [\A] [\W] \$ "
so when I run commands, I get some nice visual feedback:
:) mycomputer [23:03] [~] $ sh -c 'exit 0'
:) mycomputer [23:03] [~] $ sh -c 'exit 11'
:( 11 mycomputer [23:03] [~] $
edit: this is something I put in my ~/.bashrc
Solution 4
up N
jump N directories up in the directory tree
Instead of typing
cd ../../../..
you just type
up 4
and a
cd -
will bring you back
Put the function into your .bashrc to use it.
# (c) 2007 stefan w. GPLv3
function up {
ups=""
for i in $(seq 1 $1)
do
ups=$ups"../"
done
cd $ups
}
Solution 5
.zshrc
:
alias l='ls -CF'
alias ll='ls -ClhF'
alias la='ls -CaF'
alias lla='ls -CalhF'
alias l.='ls -CAF --ignore=\*'
alias ll.='ls -CAlhF --ignore=\*'
alias t='tree -C'
PS1=$'%{\e[0;33m%}%m %{\e[32;1m%}%~ %{\e[0;31m%}%#%{\e[m%} '
bindkey '^[[3~' delete-char
export GREP_OPTIONS="--color"
.xmodmaprc
:
clear lock
keycode 9 = Caps_Lock ISO_Next_Group Caps_Lock ISO_Next_Group
keycode 66 = Escape NoSymbol Escape
add lock = Caps_Lock
(Swaps Escape and Caps Lock keys).
Related videos on Youtube
![San](https://i.stack.imgur.com/3Fwjr.jpg?s=256&g=1)
San
Updated on September 17, 2022Comments
-
San almost 2 years
I know some people have some startup scripts and some people personalise the prompt. One developer uses short aliases for the long path he often visits and the frequent commands he runs.
What are all the effective customization you have done on your UNIX profile to increase productivity and ease of use?
-
Adam Mills over 13 yearsshould be CW, cant be answered objectively.
-
San over 13 yearsI agree. However, there was no option for CW. :-(
-
San over 13 years@akira @Michael I face this situation often. It would be great if moderators could edit/cross-post/redirect the question. Because the comment you leave doesn't help the user much in order to achieve what he really want. No offence, just a suggestion. Hope you understand.
-
-
wag over 13 years+1 for remapping of keys, my Caps Lock is mapped to Return, WHO NEEDS CAPS LOCK ANYWAY?
-
polemon over 13 yearsI'm a Vim user. It's typical for Vim users, to map Escape to Caps Lock. Emacs user tend to map Control to Caps Lock.
-
VxJasonxV over 13 yearsYour answer should probably be a comment... Like this!
-
Mikel over 13 yearsFWIW, the filename completion is
Esc``Esc
orEsc``=
inksh
, andTab
works inksh93
. Just in case anyone is stuck with it or prefers it. -
San over 13 yearsGreat tips which I never knew.
-
San over 13 yearsQuite interesting. But, I have a doubt. Where should the code reside?
-
San over 13 yearsI loved the mcd option. Nice one, Thanks.
-
Mikel over 13 yearsIn
.bashrc
presumably. -
jsbillings over 13 yearsyes, that's in my ~/.bashrc
-
San over 13 yearsWill try that..
-
maaartinus over 13 yearsMy calculator is
alias py='PYTHONSTARTUP=~/.pythonstartup python'
withfrom math import *;
in that file. The integer-division problem remains unsolved, but it's way more usable for more complex operations. -
maaartinus over 13 years+1 I've been using my version of
mcd
for many years and am going to add something likemtd
soon. -
maaartinus over 13 yearsI defined my
mtd() { mcd $TMP/`date +%y%m%d-%H%M%S-%N`; }
. It probably lacks a portability, but it's good enough for me. -
San about 13 yearsWow.. that's a nice idea..