7May/180
colorful bash prompt with git branch
Edit .bashrc
:
export COLOR_NC='\e[0m' # No Color export COLOR_WHITE='\e[1;37m' export COLOR_BLACK='\e[0;30m' export COLOR_BLUE='\e[0;34m' export COLOR_LIGHT_BLUE='\e[1;34m' export COLOR_GREEN='\e[0;32m' export COLOR_LIGHT_GREEN='\e[1;32m' export COLOR_CYAN='\e[0;36m' export COLOR_LIGHT_CYAN='\e[1;36m' export COLOR_RED='\e[0;31m' export COLOR_LIGHT_RED='\e[1;31m' export COLOR_PURPLE='\e[0;35m' export COLOR_LIGHT_PURPLE='\e[1;35m' export COLOR_BROWN='\e[0;33m' export COLOR_YELLOW='\e[1;33m' export COLOR_GRAY='\e[0;30m' export COLOR_LIGHT_GRAY='\e[0;37m' function parse_git_dirty { [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*" } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" } PS1="" PS1=$PS1"\[$COLOR_GREEN\]\u@\h\:" # Display user@host #PS1=$PS1"\[$Yellow\]\@:" # Display time #PS1=$PS1"\[$Blue\][\[$Cyan\]\d\[$Blue\]] " # Display date #PS1=$PS1"\[$Yellow\]\@:" # Display time PS1=$PS1"\[$COLOR_CYAN\]\w" # Display pwd PS1=$PS1"\[$COLOR_BROWN\]"'$(parse_git_branch)' # Display git-branch PS1=$PS1"\[$COLOR_NC\]$ " # Turn off color and end prompt export PS1=$PS1
15Feb/150
LUKS with remote header, encrypted key
# create encrypted key export GPG_TTY=$(tty) dd if=/dev/urandom bs=8388607 count=1 | gpg --symmetric --cipher-algo AES256 --output KEY.gpg # allocate empty file for hader with size truncate -s 2M HEADER.img #encrypt # NOTE: the LUKS header will be overriden with mkfs gpg --decrypt KEY.gpg | cryptsetup --cipher serpent-xts-plain64 --key-size 512 --hash sha512 --header HEADER.img --key-file - luksFormat DEV #check result (instead of DEv it is the header) cryptsetup luksDump HEADER.img #add fallback password if the KEYFILE is lost (to the header not to DEV) mkfifo /tmp/gpgpipe gpg --decrypt KEYFILE | cat - >/tmp/KEYFILE2 cryptsetup --key-file /tmp/KEYFILE2 luksAddKey HEADER.img rm -vf /tmp/KEYFILE2 #open gpg --decrypt KEY.gpg | cryptsetup --header HEADER.img --key-file - open DEV enc # and close cryptsetup close enc
15Feb/150
block device from file
Mounting a loopback device.
In the kernel config, CONFIG_BLK_DEV_LOOP
needs to be set.
# Check the used devices: losetup -a # Create the file dd if=/dev/zero of=FILENAME bs=1024k count=MEGABYTES # Attach loopback device to file losetup /dev/loopN FILENAME # Creating filesystem on device mkfs.ext3 /dev/loopN # Mounting dev mount /dev/loopN MOUNTPOINT # umount umount MOUNTPOINT # detach losetup -d /dev/loopN
14Aug/140
create file with given size (filled with zeros)
dd if=/dev/zero of=FILENAME bs=1024k count=MEGABYTES #or truncate -s 2M FILE
28Jul/140
replace string in dir
grep -rl STRING1 . | xargs ^Cd -i 's/STRING1/STRING2/g'
Note: This replaces STRING1 to STRING2 even in hidden dirs, which can mess up your .git/index
22May/140
non interactive gdb to run & backtrace
set confirm off
can turn off the "Quit anyway? (y or n)" question.
gdb EXECUTABLE -ex "set width 1000" -ex "thread apply all bt" -ex run -ex bt -ex "set confirm off" -ex quit
6Mar/140
update all packages under same category (for example KDE) with emerge
from eix --help
:
-#, --only-names --pure-packages with format/ -I, --installed Next expression only matches installed packages. -C, --category category
The emerge
command:
emerge -av $(eix -I#C kde-base)
25Oct/130
git auto-completion
wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion.bash source ~/.git-completion.bash
22Feb/130
bash basics
Executing programs in parallel:
p1 ; p2 ; p3 ; ...
Note: use wait
if inside a script, so it waits for each child to finish.
Executing programs sequentially:
p1 ; p2 ; p3 ; ...
Executing programs sequentially, stop if one fails:
p1 && p2 && p3 && ...