Minor change on bash config

This commit is contained in:
Thomas Dehaeze 2019-05-30 16:48:02 +02:00
parent 78b41761c6
commit c4300c08d3

View File

@ -2,22 +2,27 @@
* Bashrc * Bashrc
:PROPERTIES: :PROPERTIES:
:header-args:conf: :tangle ~/.bashrc :header-args:bash: :tangle ~/.bashrc
:header-args:conf+: :comments both :mkdirp yes :header-args:bash+: :comments both :mkdirp yes
:END: :END:
** TODO What does that do? ** TODO What does that do?
#+BEGIN_SRC conf #+BEGIN_SRC bash
[[ $- != *i* ]] && return [[ $- != *i* ]] && return
#+END_SRC #+END_SRC
** Bash Completion ** Bash Completion
#+BEGIN_SRC conf #+BEGIN_SRC bash
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion [ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
#+END_SRC #+END_SRC
** Ignore case for autocompletion
#+BEGIN_SRC bash
bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"
#+END_SRC
** Change the window title of X terminals ** Change the window title of X terminals
#+BEGIN_SRC conf #+BEGIN_SRC bash
case ${TERM} in case ${TERM} in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*) xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"' PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
@ -29,7 +34,7 @@ esac
#+END_SRC #+END_SRC
** Use Color ** Use Color
#+BEGIN_SRC conf #+BEGIN_SRC bash
use_color=true use_color=true
alias ls='ls -hN --color=auto --group-directories-first' alias ls='ls -hN --color=auto --group-directories-first'
alias grep='grep --colour=auto' alias grep='grep --colour=auto'
@ -38,7 +43,7 @@ esac
** TODO Set colorful PS1 only on colorful terminals. ** TODO Set colorful PS1 only on colorful terminals.
dircolors --print-database uses its own built-in database instead of using /etc/DIR_COLORS. Try to use the external file first to take advantage of user additions. Use internal bash globbing instead of external grep binary. dircolors --print-database uses its own built-in database instead of using /etc/DIR_COLORS. Try to use the external file first to take advantage of user additions. Use internal bash globbing instead of external grep binary.
#+BEGIN_SRC conf #+BEGIN_SRC bash
safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
match_lhs="" match_lhs=""
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)" [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
@ -73,11 +78,11 @@ dircolors --print-database uses its own built-in database instead of using /etc/
fi fi
#+END_SRC #+END_SRC
#+BEGIN_SRC conf #+BEGIN_SRC bash
unset use_color safe_term match_lhs sh unset use_color safe_term match_lhs sh
#+END_SRC #+END_SRC
#+BEGIN_SRC conf #+BEGIN_SRC bash
xhost +local:root > /dev/null 2>&1 xhost +local:root > /dev/null 2>&1
complete -cf sudo complete -cf sudo
@ -94,15 +99,20 @@ shopt -s autocd
shopt -s histappend shopt -s histappend
#+END_SRC #+END_SRC
** Prompt
#+BEGIN_SRC bash
export PS1="\[$(tput bold)\]\[$(tput setaf 1)\][\[$(tput setaf 3)\]\u\[$(tput setaf 2)\]@\[$(tput setaf 4)\]\h \[$(tput setaf 5)\]\W\[$(tput setaf 1)\]]\[$(tput setaf 7)\]\\$ \[$(tput sgr0)\]"
#+END_SRC
** Rebind up and down arrow keys to search through bash history ** Rebind up and down arrow keys to search through bash history
#+BEGIN_SRC conf #+BEGIN_SRC bash
bind '"\e[A": history-search-backward' bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward' bind '"\e[B": history-search-forward'
#+END_SRC #+END_SRC
** Aliases ** TODO Aliases
*** Better defaults for some commands *** Better defaults for some commands
#+BEGIN_SRC conf #+BEGIN_SRC bash
alias cp="cp -i" # confirm before overwriting something alias cp="cp -i" # confirm before overwriting something
alias df='df -h' # human-readable sizes alias df='df -h' # human-readable sizes
alias free='free -m' # show sizes in MB alias free='free -m' # show sizes in MB
@ -110,7 +120,7 @@ bind '"\e[B": history-search-forward'
#+END_SRC #+END_SRC
*** One letter aliases *** One letter aliases
#+BEGIN_SRC conf #+BEGIN_SRC bash
alias r="ranger" alias r="ranger"
alias t="tmux" alias t="tmux"
alias v="nvim" alias v="nvim"
@ -123,44 +133,44 @@ bind '"\e[B": history-search-forward'
#+END_SRC #+END_SRC
*** Neovim *** Neovim
#+begin_src conf #+begin_src bash
command -v nvim >/dev/null && alias vim="nvim" vimdiff="nvim -d" # Use neovim for vim if present. command -v nvim >/dev/null && alias vim="nvim" vimdiff="nvim -d" # Use neovim for vim if present.
#+end_src #+end_src
*** Magit *** Magit
#+BEGIN_SRC conf #+BEGIN_SRC bash
# alias magit="emacsclient -create-frame --alternate-editor=\"\" --eval '(magit-status)'" # alias magit="emacsclient -create-frame --alternate-editor=\"\" --eval '(magit-status)'"
alias magit="nvim -c MagitOnly" alias magit="nvim -c MagitOnly"
#+END_SRC #+END_SRC
*** Vim-like *** Vim-like
#+BEGIN_SRC conf #+BEGIN_SRC bash
alias :q=exit alias :q=exit
alias :e=nvim alias :e=nvim
#+END_SRC #+END_SRC
*** Youtube *** Youtube
#+BEGIN_SRC conf #+BEGIN_SRC bash
alias yt="youtube-dl --add-metadata -ic" # Download video link alias yt="youtube-dl --add-metadata -ic" # Download video link
alias yta="yt -x -f bestaudio/best" # Download only audio alias yta="yt -x -f bestaudio/best" # Download only audio
#+END_SRC #+END_SRC
*** Print each PATH entry on a separate line *** Print each PATH entry on a separate line
#+BEGIN_SRC conf #+BEGIN_SRC bash
alias path='echo -e ${PATH//:/\\n}' alias path='echo -e ${PATH//:/\\n}'
#+END_SRC #+END_SRC
*** TODO [#B] IP addresses - Remove the use of =dig= and =ifconfig= *** TODO [#B] IP addresses - Remove the use of =dig= and =ifbashig=
Use =addr= instead Use =addr= instead
#+BEGIN_SRC conf #+BEGIN_SRC bash
# alias ip="dig +short myip.opendns.com @resolver1.opendns.com" # alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
# alias localip="ip route get 8.8.4.4 | head -1 | awk '{print $7}'" # alias localip="ip route get 8.8.4.4 | head -1 | awk '{print $7}'"
# alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'" # alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
#+END_SRC #+END_SRC
** Functions ** TODO Functions
*** Display colors *** Display colors
#+BEGIN_SRC conf #+BEGIN_SRC bash
colors() { colors() {
local fgc bgc vals seq0 local fgc bgc vals seq0
@ -192,8 +202,8 @@ colors() {
*** TODO Meteo - Is Dig mandatory? *** TODO Meteo - Is Dig mandatory?
To install =dig=, use =yay -S bind-tools= To install =dig=, use =yay -S bind-tools=
#+BEGIN_SRC conf #+BEGIN_SRC bash
meteo() { meteo() {
if [ -n "$*" ]; then if [ -n "$*" ]; then
address="wttr.in/" address="wttr.in/"
address+=$* address+=$*
@ -205,12 +215,12 @@ meteo() {
address+="?lang=fr" address+="?lang=fr"
curl "$address" curl "$address"
fi fi
} }
alias meteo=meteo alias meteo=meteo
#+END_SRC #+END_SRC
*** TODO Upload using transfer.sh *** TODO Upload using transfer.sh
#+BEGIN_SRC conf #+BEGIN_SRC bash
upload() { upload() {
# write to output to tmpfile because of progress bar # write to output to tmpfile because of progress bar
tmpfile=$(mktemp -t transferXXX) tmpfile=$(mktemp -t transferXXX)
@ -224,7 +234,7 @@ alias meteo=meteo
#+END_SRC #+END_SRC
*** TODO Upload alternative *** TODO Upload alternative
#+BEGIN_SRC conf #+BEGIN_SRC bash
transfer() { transfer() {
curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename $1) | xclip -in -selection clipboard; curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename $1) | xclip -in -selection clipboard;
} }
@ -234,7 +244,7 @@ alias meteo=meteo
*** Extract archive *** Extract archive
usage: ex <file> usage: ex <file>
#+BEGIN_SRC conf #+BEGIN_SRC bash
ex () ex ()
{ {
if [ -f $1 ] ; then if [ -f $1 ] ; then
@ -264,22 +274,22 @@ the =.git= directory, listing directories first. The output gets piped into
=less= with options to preserve color and line numbers, unless the output is =less= with options to preserve color and line numbers, unless the output is
small enough for one screen. small enough for one screen.
#+BEGIN_SRC conf #+BEGIN_SRC bash
function tre() { function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX; tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
} }
#+END_SRC #+END_SRC
*** Create a new directory and enter it *** Create a new directory and enter it
#+BEGIN_SRC conf #+BEGIN_SRC bash
function mkd() { function mkd() {
mkdir -p "$@" && cd "$_"; mkdir -p "$@" && cd "$_";
} }
#+END_SRC #+END_SRC
*** Filesize of directory *** Filesize of directory
#+BEGIN_SRC conf #+BEGIN_SRC bash
function fs() { function fs() {
if du -b /dev/null > /dev/null 2>&1; then if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh; local arg=-sbh;
else else
@ -290,47 +300,20 @@ function fs() {
else else
du $arg .[^.]* ./*; du $arg .[^.]* ./*;
fi; fi;
} }
#+END_SRC #+END_SRC
*** Redirect both standard output and standard error, as well as sending to background *** Redirect both standard output and standard error, as well as sending to background
#+BEGIN_SRC conf #+BEGIN_SRC bash
function nullify() { function nullify() {
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
#+END_SRC
** Prompt
#+BEGIN_SRC conf
export PS1="\[$(tput bold)\]\[$(tput setaf 1)\][\[$(tput setaf 3)\]\u\[$(tput setaf 2)\]@\[$(tput setaf 4)\]\h \[$(tput setaf 5)\]\W\[$(tput setaf 1)\]]\[$(tput setaf 7)\]\\$ \[$(tput sgr0)\]"
#+END_SRC
** Exports
#+BEGIN_SRC conf
export TERM=xterm-256color
#+END_SRC
*** Better yaourt colors
#+BEGIN_SRC conf
export YAOURT_COLORS="nb=1:pkg=1:ver=1;32:lver=1;45:installed=1;42:grp=1;34:od=1;41;5:votes=1;44:dsc=0:other=1;35"
#+END_SRC
*** Use Ripgrep for FZF
#+BEGIN_SRC conf
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
#+END_SRC
*** Goland
#+BEGIN_SRC conf
export GOPATH=$HOME/go
PATH=$GOPATH:$GOPATH/bin:$PATH
export PATH
#+END_SRC #+END_SRC
** Bash History ** Bash History
Undocumented feature which sets the size to "unlimited". http://stackoverflow.com/questions/9457233/unlimited-bash-history Undocumented feature which sets the size to "unlimited". http://stackoverflow.com/questions/9457233/unlimited-bash-history
#+BEGIN_SRC conf #+BEGIN_SRC bash
export HISTFILESIZE= export HISTFILESIZE=
export HISTSIZE= export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] " export HISTTIMEFORMAT="[%F %T] "
@ -338,38 +321,25 @@ Undocumented feature which sets the size to "unlimited". http://stackoverflow.co
Change the file location because certain bash sessions truncate =.bash_history= file upon close. http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login Change the file location because certain bash sessions truncate =.bash_history= file upon close. http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
#+BEGIN_SRC conf #+BEGIN_SRC bash
export HISTFILE=~/.bash_eternal_history export HISTFILE=~/.bash_eternal_history
#+END_SRC #+END_SRC
Force prompt to write history after every command. http://superuser.com/questions/20900/bash-history-loss Force prompt to write history after every command. http://superuser.com/questions/20900/bash-history-loss
#+BEGIN_SRC conf #+BEGIN_SRC bash
PROMPT_COMMAND="history -a; $PROMPT_COMMAND" PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
#+END_SRC #+END_SRC
** Base16 Shell
#+BEGIN_SRC conf
BASE16_SHELL="$HOME/.base16-manager/chriskempson/base16-shell/"
[ -n "$PS1" ] && \
[ -s "$BASE16_SHELL/profile_helper.sh" ] && \
eval "$("$BASE16_SHELL/profile_helper.sh")"
#+END_SRC
* Bash Profile * Bash Profile
:PROPERTIES: :PROPERTIES:
:header-args:conf: :tangle ~/.bash_profile :header-args:bash: :tangle ~/.bash_profile
:header-args:conf+: :comments both :mkdirp yes :header-args:bash+: :comments both :mkdirp yes
:END: :END:
** Ignore case for autocompletion
#+BEGIN_SRC conf
bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"
#+END_SRC
** Source bashrc #+BEGIN_SRC bash
#+BEGIN_SRC conf [[ -f ~/.profile ]] && . ~/.profile
[[ -f ~/.bashrc ]] && . ~/.bashrc [[ -f ~/.bashrc ]] && . ~/.bashrc
#+END_SRC #+END_SRC
* Profile * Profile
@ -380,13 +350,13 @@ bind "set show-all-if-ambiguous on"
** QT And GTK Themes ** QT And GTK Themes
#+BEGIN_SRC conf #+BEGIN_SRC conf
export QT_QPA_PLATFORMTHEME="qt5ct" export QT_QPA_PLATFORMTHEME="qt5ct"
export GTK2_RC_FILES="$HOME/.gtkrc-2.0" export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
#+END_SRC #+END_SRC
** Gui program to ask for sudo password ** Gui program to ask for sudo password
#+BEGIN_SRC conf #+BEGIN_SRC conf
export SUDO_ASKPASS=~/bin/askpass-rofi export SUDO_ASKPASS=~/bin/askpass-rofi
#+END_SRC #+END_SRC
** Default ** Default
@ -398,10 +368,37 @@ export SUDO_ASKPASS=~/bin/askpass-rofi
export FILE="vifm" export FILE="vifm"
#+END_SRC #+END_SRC
** Exports
#+BEGIN_SRC conf
export TERM=xterm-256color
#+END_SRC
*** dpi config for Alacritty
#+begin_src conf
export WINIT_HIDPI_FACTOR=1.
#+end_src
*** Better yaourt colors
#+BEGIN_SRC conf
export YAOURT_COLORS="nb=1:pkg=1:ver=1;32:lver=1;45:installed=1;42:grp=1;34:od=1;41;5:votes=1;44:dsc=0:other=1;35"
#+END_SRC
*** Use Ripgrep for FZF
#+BEGIN_SRC conf
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
export FZF_DEFAULT_OPTS='--layout=reverse --height=20'
#+END_SRC
*** Goland
#+BEGIN_SRC conf
export GOPATH=$HOME/go
#+END_SRC
** Path ** Path
#+BEGIN_SRC conf #+BEGIN_SRC conf
PATH=$HOME/appimages:$PATH PATH=$HOME/appimages:$PATH
PATH=$HOME/.gem/ruby/2.5.0/bin:$PATH PATH=$HOME/.gem/ruby/2.5.0/bin:$PATH
PATH=$GOPATH:$GOPATH/bin:$PATH
PATH=~/bin:$PATH PATH=~/bin:$PATH
export PATH export PATH
#+END_SRC #+END_SRC