Last active
December 7, 2016 18:20
-
-
Save adoussot/54514f3d629c38038a4de0f3a0dad3a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# backup folder to hardrive | |
backup() { | |
rsync -rltgoDv --ignore-errors --force $HOME /media/$USER/drive | |
} | |
# command to rename the current terminal emulator tab | |
prompt() { | |
echo -e '\033]2;'$1'\007' | |
} | |
# Function to assemble the Git part of our prompt. | |
git_prompt () | |
{ | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
if git diff --quiet 2>/dev/null >&2; then | |
git_color="$c_git_clean" | |
else | |
git_color="$c_git_dirty" | |
fi | |
echo " [$git_color$git_branch${c_reset}]" | |
} | |
# Thy holy prompt. | |
PROMPT_COMMAND='PS1="${c_user}\u${c_reset}@${c_user}\h${c_reset}:${c_path}\w${c_reset}$(git_prompt)\$ "' | |
# Command to extract compressed files in the current directory | |
# Thanks to that awesome posts: http://sametmax.com/a-linterieur-de-mon-bashrc/ | |
extract () { | |
if [ -f $1 ] | |
then | |
case $1 in | |
(*.7z) 7z x $1 ; echo " 7z x $1" ;; | |
(*.lzma) unlzma $1 ; echo " unlzma x $1" ;; | |
(*.rar) unrar x $1 ; echo " unrar x $1" ;; | |
(*.tar) tar xvf $1 ; echo " tar xvf $1" ;; | |
(*.tar.bz2) tar xvjf $1; echo " tar xvjf $1" ;; | |
(*.bz2) bunzip2 $1 ; echo " bunzip2 $1" ;; | |
(*.tar.gz) tar xvzf $1; echo " tar xvzf $1";; | |
(*.gz) gunzip $1 ; echo " gunzip $1";; | |
(*.tar.xz) tar Jxvf $1; echo " tar Jxvf $1";; | |
(*.xz) xz -d $1 ; echo " xz -d $1";; | |
(*.tbz2) tar xvjf $1 ; echo " tar xvjf $1";; | |
(*.tgz) tar xvzf $1 ; echo " tar xvzf $1";; | |
(*.zip) unzip $1 ; echo " unzip $1";; | |
(*.Z) uncompress ; echo " uncompress $1";; | |
(*) echo "don't know how to extract '$1'..." ;; | |
esac | |
else | |
echo "Error: '$1' is not a valid file!" | |
#exit 0 | |
fi | |
} | |
# Create a symbolic link in order to link executable program to | |
# a directory which has been previously added to PATH variable | |
lns() { | |
if [[ "$1" == \/* ]]; | |
then | |
path="$1" | |
else | |
path=`pwd`"/""$1" | |
fi | |
echo "$path" | |
ln -sf "$path" ~/bin | |
} | |
# Mount DDR after editting /etc/fstab: example (nano /etc/fstab) | |
# UUID=13ea474a-fb27-4c91-bae7-c45690f88954 /media/user/sda6 ext4 errors=remount-ro 0 1 | |
mtdata() { | |
mount_ddr="/dev/sda6" | |
if grep "$mount_ddr" /proc/mounts; then | |
echo "$mount_ddr is already mounted." | |
else | |
sudo mount "$mount_ddr" | |
if [ $? -eq 0 ]; then | |
echo "Mount succeeded!"; | |
fi | |
fi | |
} | |
umtdata() { | |
to_umount="/dev/sda6" | |
if grep "$to_umount" /proc/mounts; then | |
sudo umount "$to_umount" | |
if [ $? -eq 0 ]; then | |
echo "Umount succeeded!"; | |
fi | |
else | |
echo "$to_umount"" isn't mounted" | |
fi | |
} | |
# Mount DDR without editting /etc/fstab file | |
mt() { | |
mount_ddr="$1" | |
mount_dest="$2" | |
if (! grep -q "$mount_ddr" /etc/mtab); then | |
sudo mkdir -m 777 "$mount_dest" && | |
sudo chown -R $USER "$mount_dest" && | |
sudo chgrp -R $USER "$mount_dest" && | |
sudo mount "$mount_ddr" "$mount_dest" #-o uid=100,gid=1000,utf8,dmask=027,fmask=137 | |
# test the last command's PID | |
if [ $? -eq 0 ]; then | |
echo "Mount succeeded!" | |
else | |
echo "Something went wrong with the mount..." | |
fi | |
else | |
echo "Error: ""$mount_ddr""is not a valid file!" | |
fi | |
} | |
umt() { | |
to_umount="$1" | |
if (grep -q "$to_umount" /etc/mtab ); then | |
sudo umount "$to_umount" | |
sudo rm -r "$to_umount" | |
echo "file $to_umount suppress" | |
else | |
echo "grep -q $to_umount /etc/mtab"; | |
fi | |
} | |
# sanetize file name (replace space by _ or -) | |
san() { | |
element="$1" | |
if [ -d "$element" ]; then | |
newName="${element// /-}" | |
elif [ -f "$element" ]; then | |
newName="${element// /_}" | |
else | |
echo "Abord: not a standard file type" | |
fi | |
if [ ! -z "$newName" ]; then | |
read -r -p "Do you want to rename ""$element"" to ""$newName"" [Y/n]" response | |
response="${response,,}" # to lower case | |
if [[ $response =~ ^(yesy|y) ]]; then | |
mv "$element" "$newName" | |
fi | |
fi | |
} | |
# ripgrep search | |
rgp() { | |
rg -A "$1" -B "$1" -in "$2" | |
} | |
# XFCE specific commands | |
# sleep the session | |
slp() { | |
xfce4-session-logout --suspend | |
} | |
# open a new tab at a specific directory and change | |
# the tab name according t the directory | |
alposts() { | |
xfce4-terminal --tab -T "aldo-posts" --working-directory="$HOME/.../aldo-posts" | |
} | |
######## ALIAS ########## | |
alias sshot="xfce4-screenshooter -r" | |
alias bashrc="subl ~/.bashrc" | |
alias refresh=". ~/.bashrc" | |
alias exbin="export PATH=$PATH:$(npm bin)" | |
alias ..='cd ..' | |
alias ...='cd ../../' | |
alias ....='cd ../../../' | |
alias .....='cd ../../../../' | |
alias ......='cd ../../../../../' | |
alias path="echo \"${PATH//:/$'\n'}\"" | |
alias m2="cd \"$REPOSITORY_PATH\" && prompt 'M2'" | |
alias mci="mvn clean install; ntf" | |
alias mvntestperso="mvn test -Denvironment=perso > \"$TEMP\temp.txt\" && subl \"$TEMP\temp.txt\"; ntf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment