Everything as scripts and no more as functions!
Bashrc load time : 0.049s → 0.016s
This commit is contained in:
parent
7f7b011d4a
commit
1c14947329
19 changed files with 1007 additions and 718 deletions
181
bashrc
181
bashrc
|
@ -1,61 +1,68 @@
|
|||
# Custom scripts
|
||||
#
|
||||
# ~/.bashrc
|
||||
#
|
||||
|
||||
# ENVIRONMENT VARIABLES
|
||||
|
||||
|
||||
#find ~/.scripts/ ~/.gscripts/ -type f -name "*.sh" | while read script; do
|
||||
#source "$script"
|
||||
#done
|
||||
[ -f ~/.scripts/index.sh ] && source ~/.scripts/index.sh
|
||||
[ -f ~/.gscripts/index.sh ] && source ~/.gscripts/index.sh
|
||||
|
||||
# Prompt
|
||||
if [[ $USER == 'root' ]]; then
|
||||
col=31;
|
||||
elif [[ -n $ME ]]; then # $ME is a var set by my private config that is not empty if it is my account (and not a system account e.g. `git`)
|
||||
col=32;
|
||||
else
|
||||
col=33;
|
||||
fi
|
||||
|
||||
export USER=$(whoami)
|
||||
PS1="\[\e]2;\u@\h \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
|
||||
PS2="> "
|
||||
PS3="+ "
|
||||
PS4="- "
|
||||
|
||||
|
||||
# Vars
|
||||
export PAGER=less
|
||||
export EDITOR=vim
|
||||
export VISUAL=vim
|
||||
export BROWSER=/usr/bin/qutebrowser
|
||||
# Region preferences
|
||||
export LANG=fr_FR.utf8
|
||||
export TZ=/usr/share/zoneinfo/Europe/Paris
|
||||
|
||||
export PATH="$PATH"
|
||||
# Favourite commands
|
||||
export PAGER=less
|
||||
export EDITOR=vim
|
||||
export VISUAL=gvim
|
||||
export BROWSER=qutebrowser
|
||||
|
||||
# Some programs need those changes
|
||||
if [ -d $HOME/.gem/ruby ]; then
|
||||
$(which ls) $HOME/.gem/ruby | while read rubyVer; do
|
||||
ls $HOME/.gem/ruby | while read rubyVer; do
|
||||
export PATH="$PATH:$HOME/.gem/ruby/$rubyVer/bin/"
|
||||
done
|
||||
fi
|
||||
export PATH="$(echo "$PATH" | sed 's|:|\n|g' | sort | uniq | tr '\n' ':' | sed 's|:$||')"
|
||||
export LANG=fr_FR.utf8
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=${HISTSIZE}
|
||||
export HISTCONTROL=ignoreboth
|
||||
#export PATH="$(echo "$PATH" | sed 's|:|\n|g' | sort | uniq | tr '\n' ':' | sed 's|:$||')"
|
||||
export JAVA_FONTS=/usr/share/fonts/TTF
|
||||
export ANDROID_HOME=/opt/android-sdk
|
||||
export GOPATH=$HOME/.go
|
||||
export XDG_CONFIG_HOME=$HOME/.config
|
||||
|
||||
if [ -z $XDG_CONFIG_HOME ]; then
|
||||
export XDG_CONFIG_HOME=$HOME/.config
|
||||
# ALIASES
|
||||
|
||||
# Completion for existing commands
|
||||
export LS_OPTIONS='--group-directories-first --time-style=+"%d/%m/%Y %H:%M" --color=auto --classify --human-readable'
|
||||
alias ls="ls $LS_OPTIONS"
|
||||
alias grep='grep --color=tty -d skip'
|
||||
alias mkdir='mkdir -v'
|
||||
alias cp="cp -i"
|
||||
alias mv="mv -iv"
|
||||
alias dd='dd status=progress'
|
||||
alias rm='rm -Iv --one-file-system'
|
||||
alias free='free -m'
|
||||
alias df='df -h'
|
||||
alias pacman='pacman --color auto'
|
||||
|
||||
# Shortcuts for commonly used commands
|
||||
alias ll="ls -l $LS_OPTIONS"
|
||||
alias la="ls -la $LS_OPTIONS"
|
||||
alias al=sl
|
||||
alias x='startx; logout'
|
||||
alias s='sudo -s -E'
|
||||
alias po='proxy off'
|
||||
alias nw="sudo systemctl restart NetworkManager"
|
||||
alias mc="machines"
|
||||
|
||||
# Superseding commands with better ones if they are present
|
||||
if which vim &> /dev/null; then
|
||||
alias vi='vim'
|
||||
fi
|
||||
if which gopass &> /dev/null; then
|
||||
alias pass='gopass'
|
||||
fi
|
||||
if which wakeonlan &> /dev/null; then
|
||||
alias wol='wakeonlan'
|
||||
fi
|
||||
|
||||
# Tweaks
|
||||
[[ $- != *i* ]] && return
|
||||
|
||||
if [ -f /etc/bash_completion ]; then . /etc/bash_completion; fi
|
||||
|
||||
xhost +local:root > /dev/null 2>&1
|
||||
# SHELL CUSTOMIZATION
|
||||
|
||||
complete -cf sudo
|
||||
|
||||
|
@ -68,71 +75,41 @@ shopt -s extglob
|
|||
shopt -s histappend
|
||||
shopt -s hostcomplete
|
||||
|
||||
export LS_OPTIONS='--group-directories-first --time-style=+"%d/%m/%Y %H:%M" --color=auto --classify --human-readable'
|
||||
alias ls="ls $LS_OPTIONS"
|
||||
alias ll="ls -l $LS_OPTIONS"
|
||||
alias la="ls -la $LS_OPTIONS"
|
||||
alias al=sl
|
||||
alias grep='grep --color=tty -d skip'
|
||||
alias mkdir='mkdir -v'
|
||||
alias cp="cp -i"
|
||||
alias mv="mv -iv"
|
||||
alias dd='dd status=progress'
|
||||
alias rm='rm -Iv --one-file-system'
|
||||
alias free='free -m'
|
||||
alias df='df -h'
|
||||
alias 49.3='sudo'
|
||||
alias pacman='pacman --color auto'
|
||||
alias x='startx; logout'
|
||||
alias s='sudo -s -E'
|
||||
export HISTSIZE=10000
|
||||
export HISTFILESIZE=${HISTSIZE}
|
||||
export HISTCONTROL=ignoreboth
|
||||
|
||||
if which gopass &> /dev/null; then
|
||||
alias pass='gopass'
|
||||
# PROMPT CUSTOMIZATION
|
||||
|
||||
if [[ $USER == 'root' ]]; then
|
||||
col=31;
|
||||
elif [[ $USER == 'geoffrey' || $USER == 'gbontoux' || $USER == 'gpreud' ]]; then
|
||||
col=32;
|
||||
else
|
||||
col=33;
|
||||
fi
|
||||
PS1="\[\e]2;\u@\h \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
|
||||
PS2="> "
|
||||
PS3="+ "
|
||||
PS4="- "
|
||||
|
||||
# Utils
|
||||
# UTILITIES
|
||||
|
||||
# Bash completion
|
||||
[ -f /etc/bash_completion ] && . /etc/bash_completion
|
||||
|
||||
# Command not found handlers
|
||||
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash # Arch
|
||||
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh # Arch (alternative, for Manjaro mostly)
|
||||
|
||||
# Bad day mood-saver
|
||||
if which thefuck &> /dev/null; then
|
||||
alias fuck='TF_CMD=$(TF_ALIAS=fuck PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES=$(alias) thefuck $(fc -ln -1)) && eval $TF_CMD && history -s $TF_CMD'
|
||||
alias FUCK='fuck'
|
||||
fi
|
||||
|
||||
# CUSTOM SCRIPTS
|
||||
|
||||
# Command not found
|
||||
[ -r /usr/share/doc/pkgfile/command-not-found.bash ] && . /usr/share/doc/pkgfile/command-not-found.bash
|
||||
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh
|
||||
export PATH="$HOME/.scripts/:$PATH"
|
||||
[ -f ~/.gscripts/gprofile ] && source ~/.gscripts/gprofile
|
||||
|
||||
# Functions
|
||||
function clean {
|
||||
find . -type d -name bower_components -or -name node_modules -print0 | while read file; do
|
||||
rm -rf "$file"
|
||||
done
|
||||
find . -type f -name Makefile -print0 | while IFS= read -r -d '' file; do
|
||||
echo "--> $file"
|
||||
(cd "${file//Makefile}"; make clean)
|
||||
done
|
||||
find . -type d -name .git -print0 | while IFS= read -r -d '' dir; do
|
||||
echo "--> $file"
|
||||
(cd "$dir"; git gc)
|
||||
done
|
||||
}
|
||||
|
||||
function dafont {
|
||||
wget "http://dl.dafont.com/dl/?f=$1" -O /tmp/dafont.zip
|
||||
unzip /tmp/dafont.zip -d ~/.local/share/fonts -x *.txt
|
||||
rm -rf /tmp/dafont.zip
|
||||
}
|
||||
|
||||
alias nw="sudo systemctl restart NetworkManager"
|
||||
|
||||
# Clears everything it can to save space
|
||||
function emergency-space {
|
||||
rm -rf $HOME/.cache
|
||||
if which pacman &> /dev/null; then
|
||||
sudo pacman -Scc
|
||||
elif which apt-get &> /deb/null; then
|
||||
sudo apt-get clean
|
||||
fi
|
||||
if which journalctl &> /dev/null; then
|
||||
sudo journalctl --vacuum-size=100M
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue