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
:PROPERTIES:
:header-args:conf: :tangle ~/.bashrc
:header-args:conf+: :comments both :mkdirp yes
:header-args:bash: :tangle ~/.bashrc
:header-args:bash+: :comments both :mkdirp yes
:END:
** TODO What does that do?
#+BEGIN_SRC conf
#+BEGIN_SRC bash
[[ $- != *i* ]] && return
#+END_SRC
** Bash Completion
#+BEGIN_SRC conf
#+BEGIN_SRC bash
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
#+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
#+BEGIN_SRC conf
#+BEGIN_SRC bash
case ${TERM} in
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
@ -29,7 +34,7 @@ esac
#+END_SRC
** Use Color
#+BEGIN_SRC conf
#+BEGIN_SRC bash
use_color=true
alias ls='ls -hN --color=auto --group-directories-first'
alias grep='grep --colour=auto'
@ -38,7 +43,7 @@ esac
** 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.
#+BEGIN_SRC conf
#+BEGIN_SRC bash
safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
match_lhs=""
[[ -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
#+END_SRC
#+BEGIN_SRC conf
#+BEGIN_SRC bash
unset use_color safe_term match_lhs sh
#+END_SRC
#+BEGIN_SRC conf
#+BEGIN_SRC bash
xhost +local:root > /dev/null 2>&1
complete -cf sudo
@ -94,15 +99,20 @@ shopt -s autocd
shopt -s histappend
#+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
#+BEGIN_SRC conf
#+BEGIN_SRC bash
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
#+END_SRC
** Aliases
** TODO Aliases
*** Better defaults for some commands
#+BEGIN_SRC conf
#+BEGIN_SRC bash
alias cp="cp -i" # confirm before overwriting something
alias df='df -h' # human-readable sizes
alias free='free -m' # show sizes in MB
@ -110,7 +120,7 @@ bind '"\e[B": history-search-forward'
#+END_SRC
*** One letter aliases
#+BEGIN_SRC conf
#+BEGIN_SRC bash
alias r="ranger"
alias t="tmux"
alias v="nvim"
@ -123,44 +133,44 @@ bind '"\e[B": history-search-forward'
#+END_SRC
*** Neovim
#+begin_src conf
#+begin_src bash
command -v nvim >/dev/null && alias vim="nvim" vimdiff="nvim -d" # Use neovim for vim if present.
#+end_src
*** Magit
#+BEGIN_SRC conf
#+BEGIN_SRC bash
# alias magit="emacsclient -create-frame --alternate-editor=\"\" --eval '(magit-status)'"
alias magit="nvim -c MagitOnly"
#+END_SRC
*** Vim-like
#+BEGIN_SRC conf
#+BEGIN_SRC bash
alias :q=exit
alias :e=nvim
#+END_SRC
*** Youtube
#+BEGIN_SRC conf
#+BEGIN_SRC bash
alias yt="youtube-dl --add-metadata -ic" # Download video link
alias yta="yt -x -f bestaudio/best" # Download only audio
#+END_SRC
*** Print each PATH entry on a separate line
#+BEGIN_SRC conf
#+BEGIN_SRC bash
alias path='echo -e ${PATH//:/\\n}'
#+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
#+BEGIN_SRC conf
#+BEGIN_SRC bash
# 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 ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
#+END_SRC
** Functions
** TODO Functions
*** Display colors
#+BEGIN_SRC conf
#+BEGIN_SRC bash
colors() {
local fgc bgc vals seq0
@ -192,25 +202,25 @@ colors() {
*** TODO Meteo - Is Dig mandatory?
To install =dig=, use =yay -S bind-tools=
#+BEGIN_SRC conf
meteo() {
if [ -n "$*" ]; then
address="wttr.in/"
address+=$*
address+="?lang=fr"
curl "$address"
else
address="wttr.in/"
address+=$(ip)
address+="?lang=fr"
curl "$address"
fi
}
alias meteo=meteo
#+BEGIN_SRC bash
meteo() {
if [ -n "$*" ]; then
address="wttr.in/"
address+=$*
address+="?lang=fr"
curl "$address"
else
address="wttr.in/"
address+=$(ip)
address+="?lang=fr"
curl "$address"
fi
}
alias meteo=meteo
#+END_SRC
*** TODO Upload using transfer.sh
#+BEGIN_SRC conf
#+BEGIN_SRC bash
upload() {
# write to output to tmpfile because of progress bar
tmpfile=$(mktemp -t transferXXX)
@ -224,7 +234,7 @@ alias meteo=meteo
#+END_SRC
*** TODO Upload alternative
#+BEGIN_SRC conf
#+BEGIN_SRC bash
transfer() {
curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename $1) | xclip -in -selection clipboard;
}
@ -234,7 +244,7 @@ alias meteo=meteo
*** Extract archive
usage: ex <file>
#+BEGIN_SRC conf
#+BEGIN_SRC bash
ex ()
{
if [ -f $1 ] ; then
@ -264,73 +274,46 @@ the =.git= directory, listing directories first. The output gets piped into
=less= with options to preserve color and line numbers, unless the output is
small enough for one screen.
#+BEGIN_SRC conf
#+BEGIN_SRC bash
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}
#+END_SRC
*** Create a new directory and enter it
#+BEGIN_SRC conf
#+BEGIN_SRC bash
function mkd() {
mkdir -p "$@" && cd "$_";
}
#+END_SRC
*** Filesize of directory
#+BEGIN_SRC conf
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
#+BEGIN_SRC bash
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
#+END_SRC
*** Redirect both standard output and standard error, as well as sending to background
#+BEGIN_SRC conf
function nullify() {
"$@" >/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
#+BEGIN_SRC bash
function nullify() {
"$@" >/dev/null 2>&1
}
#+END_SRC
** 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 HISTSIZE=
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
#+BEGIN_SRC conf
#+BEGIN_SRC bash
export HISTFILE=~/.bash_eternal_history
#+END_SRC
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"
#+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
:PROPERTIES:
:header-args:conf: :tangle ~/.bash_profile
:header-args:conf+: :comments both :mkdirp yes
:header-args:bash: :tangle ~/.bash_profile
:header-args:bash+: :comments both :mkdirp yes
: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 conf
[[ -f ~/.bashrc ]] && . ~/.bashrc
#+BEGIN_SRC bash
[[ -f ~/.profile ]] && . ~/.profile
[[ -f ~/.bashrc ]] && . ~/.bashrc
#+END_SRC
* Profile
@ -380,13 +350,13 @@ bind "set show-all-if-ambiguous on"
** QT And GTK Themes
#+BEGIN_SRC conf
export QT_QPA_PLATFORMTHEME="qt5ct"
export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
export QT_QPA_PLATFORMTHEME="qt5ct"
export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
#+END_SRC
** Gui program to ask for sudo password
#+BEGIN_SRC conf
export SUDO_ASKPASS=~/bin/askpass-rofi
export SUDO_ASKPASS=~/bin/askpass-rofi
#+END_SRC
** Default
@ -398,10 +368,37 @@ export SUDO_ASKPASS=~/bin/askpass-rofi
export FILE="vifm"
#+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
#+BEGIN_SRC conf
PATH=$HOME/appimages:$PATH
PATH=$HOME/.gem/ruby/2.5.0/bin:$PATH
PATH=$GOPATH:$GOPATH/bin:$PATH
PATH=~/bin:$PATH
export PATH
#+END_SRC