vimrc
This commit is contained in:
+241
@@ -0,0 +1,241 @@
|
||||
#!/bin/bash
|
||||
|
||||
function __prompt_command {
|
||||
local EXIT="$?" # This needs to be first
|
||||
|
||||
local R='\[\e[0m\]'
|
||||
local Red='\[\e[31m\]'
|
||||
local Gre='\[\e[32m\]'
|
||||
local Yel='\[\e[93m\]'
|
||||
local Blu='\[\e[34m\]'
|
||||
local Cya='\[\e[36m\]'
|
||||
local Mag='\[\e[95m\]'
|
||||
local Gra='\[\e[90m\]'
|
||||
|
||||
local DIVERGENT_GIT_SYMBOL="${Yel}➾${R}"
|
||||
local SYNCHRONIZED_GIT_SYMBOL="${Gre}✔${R}"
|
||||
local PUSHED_NEEDED_SYMBOL='⥱'
|
||||
local TAG_NEEDED_SYMBOL='⤽'
|
||||
|
||||
local previous_IFS="$IFS"
|
||||
|
||||
# set xterm title
|
||||
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"
|
||||
|
||||
PS1=''
|
||||
IFS=' '
|
||||
|
||||
if [[ -n ${container_hostname:-} ]]; then
|
||||
PS1+="${Gra}[LXC:${R}"
|
||||
local host
|
||||
host=$(builtin echo $container_hostname | tr ' ' ':')
|
||||
case ${host:0:4} in
|
||||
'beta')
|
||||
PS1+="${Yel}"
|
||||
;;
|
||||
'prod')
|
||||
PS1+="${Red}"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
PS1+="${host}${Gra}] "
|
||||
fi
|
||||
|
||||
if [[ "$(id -u)" -eq 0 ]]; then
|
||||
PS1+="$Yel\u$R"
|
||||
PROMPT='$'
|
||||
else
|
||||
PS1+="$Gre\u$R"
|
||||
PROMPT='#'
|
||||
fi
|
||||
|
||||
PS1+="${Gra}@"
|
||||
|
||||
case ${HOSTNAME:0:4} in
|
||||
'beta')
|
||||
PS1+="${Yel}"
|
||||
;;
|
||||
'prod')
|
||||
PS1+="${Red}"
|
||||
;;
|
||||
*)
|
||||
PS1+="${R}"
|
||||
;;
|
||||
esac
|
||||
PS1+="$HOSTNAME"
|
||||
|
||||
local pwd='~'
|
||||
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
|
||||
PS1+=" ${Cya}${pwd}$(__vte_osc7)${R}"
|
||||
|
||||
if hash git 2>&-; then
|
||||
# git command exists
|
||||
|
||||
if git rev-parse --git-dir >/dev/null 2>&1; then
|
||||
# current dir is version controlled
|
||||
|
||||
local branch tag_release dirty
|
||||
branch=$(git branch 2>/dev/null | grep -e ^* | cut -d ' ' -f2)
|
||||
PS1+=" ${R}[${Mag}${branch}${R}|"
|
||||
|
||||
tag_release=$(git describe --tags 2>/dev/null | cut -d'-' -f1)
|
||||
dirty=$(git status -s | wc -l)
|
||||
if [[ $dirty -ne 0 ]]; then
|
||||
PS1+="${Yel}${DIVERGENT_GIT_SYMBOL}${R}|${tag_release}${Yel}…$dirty"
|
||||
else
|
||||
local ahead
|
||||
ahead=$(git rev-list --branches --not --remotes | wc -l)
|
||||
|
||||
if [[ $ahead -ne 0 ]]; then
|
||||
PS1+="${DIVERGENT_GIT_SYMBOL}|${tag_release}${Yel}${PUSHED_NEEDED_SYMBOL}${ahead}"
|
||||
else
|
||||
if [[ -z $tag_release ]]; then
|
||||
PS1+="${SYNCHRONIZED_GIT_SYMBOL}"
|
||||
else
|
||||
local commit_ahead
|
||||
commit_ahead=$(git log "$tag_release"..HEAD --oneline | wc -l)
|
||||
|
||||
if [[ $commit_ahead -gt 0 ]]; then
|
||||
PS1+="${DIVERGENT_GIT_SYMBOL}|${tag_release}${Cya}${TAG_NEEDED_SYMBOL}${commit_ahead}"
|
||||
else
|
||||
PS1+="${SYNCHRONIZED_GIT_SYMBOL}|${Cya}${tag_release}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
PS1+="${R}]"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $EXIT != 0 ]; then
|
||||
PS1+="$Mag" # Add red if exit code non 0
|
||||
else
|
||||
PS1+="$Gra"
|
||||
fi
|
||||
|
||||
PS1+=" $PROMPT ${R}"
|
||||
IFS="$previous_IFS"
|
||||
}
|
||||
|
||||
function __vte_osc7 {
|
||||
# HINT: special character vte to get TILIX show proper hostname and pwd
|
||||
# Use \[...\] around the parts of PS1 that have length 0.
|
||||
# https://unix.stackexchange.com/questions/28827/why-is-my-bash-prompt-getting-bugged-when-i-browse-the-history#28828
|
||||
|
||||
VTE_INFO="${HOSTNAME:-}"
|
||||
if [[ -n ${container_hostname:-} ]]; then
|
||||
local host
|
||||
host=$(builtin echo $container_hostname | tr ' ' ':')
|
||||
VTE_INFO="$host:$HOSTNAME"
|
||||
fi
|
||||
printf "\[\033]7;file://%s%s\a\]" "${VTE_INFO}" "$(__vte_urlencode "${PWD}")"
|
||||
|
||||
}
|
||||
|
||||
function __vte_urlencode {
|
||||
# This is important to make sure string manipulation is handled
|
||||
# byte-by-byte.
|
||||
LC_ALL=C
|
||||
str="$1"
|
||||
while [ -n "$str" ]; do
|
||||
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
|
||||
printf "%s" "$safe"
|
||||
str="${str#"$safe"}"
|
||||
if [ -n "$str" ]; then
|
||||
printf "%%%02X" "'$str"
|
||||
str="${str#?}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
###------
|
||||
### MAIN
|
||||
###------
|
||||
|
||||
MIAOU_BASH_DIR=$(realpath /opt/miaou-bash)
|
||||
export MIAOU_BASH_DIR
|
||||
|
||||
## Add path for TOOLBOX if any
|
||||
[[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true
|
||||
|
||||
# Add path to any tools folder in /opt/miaou-*
|
||||
for i in {/opt,$HOME}/miaou-*/tools; do [[ -d "$i" ]] && PATH=$PATH:$i; done || true
|
||||
|
||||
# If not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return ;;
|
||||
esac
|
||||
|
||||
HOSTNAME=$(hostname -f)
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=10000
|
||||
HISTFILESIZE=20000
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
# One-liner: Do we have colors?
|
||||
if [[ -t 1 ]] && [[ "$COLORTERM" == "truecolor" || "$TERM" == *"256color"* ]]; then
|
||||
export COLOR_OPTIONS=' --color=auto'
|
||||
export LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.sql.gz=01;35:*.mariadb.gz=01;35:*.postgres.gz=01;35:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"
|
||||
fi
|
||||
|
||||
export LESS="r"
|
||||
|
||||
# enable programmable completion features (you don't need to enable
|
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||
# sources /etc/bash.bashrc).
|
||||
if ! shopt -oq posix; then
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
fi
|
||||
|
||||
# prevent CTRL+S to freeze in vim, CTRL+Q to unfreeze!
|
||||
stty -ixon
|
||||
|
||||
PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs
|
||||
|
||||
# ALIASES
|
||||
|
||||
alias sudo='sudo ' # smart sudo alias trick!
|
||||
|
||||
alias ls='ls $COLOR_OPTIONS -h'
|
||||
alias ll='ls $COLOR_OPTIONS -lh'
|
||||
alias la='ls $COLOR_OPTIONS -lah'
|
||||
alias ltr='ls $COLOR_OPTIONS -ltrh'
|
||||
alias l=ls
|
||||
|
||||
alias cd..='cd ..'
|
||||
alias ..=cd..
|
||||
|
||||
alias grep='grep $COLOR_OPTIONS '
|
||||
alias fgrep='fgrep $COLOR_OPTIONS '
|
||||
alias egrep='egrep $COLOR_OPTIONS '
|
||||
|
||||
alias transfer_cp='rsync -a --info=progress2 --no-inc-recursive'
|
||||
|
||||
# shellcheck disable=SC2142
|
||||
alias ssu="ss -ntelp | perl -pne 'if(/uid:(\\d+)/){@a=getpwuid(\$1);s/uid:(\\d+)/user:\$a[0]/}' | awk '{ print \$4 \"\\t\" \$7 \"\\t\" \$6 }'"
|
||||
|
||||
# shellcheck disable=SC2142
|
||||
alias ssu4="ss -ntel4p | perl -pne 'if(/uid:(\\d+)/){@a=getpwuid(\$1);s/uid:(\\d+)/user:\$a[0]/}' | awk '{ print \$4 \"\\t\\t\" \$7 \"\\t\\t\" \$6 }'"
|
||||
|
||||
# Alias definitions.
|
||||
[[ -f "/etc/bash.aliases" ]] && source "/etc/bash.aliases" || true
|
||||
[[ -f "$HOME/.bash_aliases" ]] && source "$HOME/.bash_aliases" || true
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
# GNU Readline main configuration file
|
||||
|
||||
set blink-matching-paren on
|
||||
set visible-stats on
|
||||
set mark-symlinked-directories on
|
||||
|
||||
## completion case insensitive and ambiguous
|
||||
set show-all-if-ambiguous on
|
||||
set skip-completed-text on
|
||||
set colored-completion-prefix on
|
||||
set colored-stats on
|
||||
set completion-ignore-case on
|
||||
set completion-prefix-display-length 15
|
||||
set completion-query-items 20
|
||||
set menu-complete-display-prefix on
|
||||
|
||||
# display characters with the eighth bit set directly
|
||||
set input-meta on
|
||||
set output-meta on
|
||||
set convert-meta off
|
||||
|
||||
## ARROW up, down for history search
|
||||
"\e[A":history-search-backward
|
||||
"\e[B":history-search-forward
|
||||
|
||||
# CTRL + Right, Left for word suppressing
|
||||
"\e[1;5C": forward-word
|
||||
"\e[1;5D": backward-word
|
||||
|
||||
# ALT + BACKSPACE for left line suppressing
|
||||
"\e[3;3~": kill-line
|
||||
# ALT + DELETE for right line suppressing
|
||||
"\e\C-?": backward-kill-line
|
||||
|
||||
# CTRL + BACKSPACE for left word suppressing
|
||||
"\C-H": backward-kill-word
|
||||
|
||||
# SHIFT + DELETE for whole line suppressing
|
||||
"\e[3;2~": kill-whole-line
|
||||
@@ -0,0 +1,6 @@
|
||||
" AZERTY quick access to basic keys
|
||||
" ---------------------------------
|
||||
nnoremap ! .
|
||||
nnoremap à 0
|
||||
nnoremap ù %
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
" Smart Defaults
|
||||
set showcmd " Show (partial) command in status line.
|
||||
set showmatch " Show matching brackets.
|
||||
set ignorecase " Do case insensitive matching
|
||||
set smartcase " Do smart case matching
|
||||
set incsearch " Incremental search
|
||||
set autowrite " Automatically save before commands like :next and :make
|
||||
set hidden " Hide buffers when they are abandoned
|
||||
set shiftwidth=2
|
||||
set tabstop=2
|
||||
set expandtab
|
||||
set number
|
||||
set relativenumber
|
||||
filetype plugin indent on
|
||||
|
||||
" Show Status
|
||||
set laststatus=2
|
||||
highlight StatusLine ctermfg=DarkGrey
|
||||
|
||||
" Wild Menu
|
||||
set wildmenu
|
||||
set wildmode=list:longest
|
||||
set wildignore=*.jpg,*.png,*.gif,*.pdf
|
||||
|
||||
" Show Cursor
|
||||
set cursorline
|
||||
highlight clear CursorLine
|
||||
highlight link CursorLine CursorColumn
|
||||
highlight CursorLineNR cterm=italic
|
||||
|
||||
" Toggle line/relative numbers
|
||||
nnoremap <F2> :set number!<CR>
|
||||
nnoremap <F3> :set relativenumber!<CR>
|
||||
highlight LineNr ctermfg=DarkGrey
|
||||
|
||||
" Sudo Write
|
||||
command! W silent execute 'write !sudo tee ' . shellescape(@%, 1) . ' >/dev/null'
|
||||
|
||||
" Jump to Last Position
|
||||
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
|
||||
@@ -0,0 +1,8 @@
|
||||
let additionals = [ "core", "miaou", "rookie", "azerty" ]
|
||||
for additional in additionals
|
||||
let s:vimrc_path = "/etc/vim/vimrc." . additional
|
||||
if filereadable(s:vimrc_path)
|
||||
execute "source " . expand(s:vimrc_path)
|
||||
endif
|
||||
endfor
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
" Detect miaou-bash
|
||||
autocmd BufReadPost,BufNewFile * if getline(1) =~# '^#!.*miaou-bash' | setlocal filetype=bash | endif
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
" ROOKIE vim user
|
||||
" ---------------
|
||||
|
||||
" Open File and Go to Line under Cursor
|
||||
nnoremap gf gF
|
||||
|
||||
" Move Along Words
|
||||
inoremap <C-Left> B
|
||||
inoremap <C-Right> W
|
||||
inoremap <M-Left> b
|
||||
inoremap <M-Right> w
|
||||
nnoremap <M-Left> b
|
||||
nnoremap <M-Right> w
|
||||
|
||||
" Move Along Paragraphs
|
||||
inoremap <C-Up> {
|
||||
inoremap <C-Down> }
|
||||
nnoremap <C-Up> {
|
||||
nnoremap <C-Down> }
|
||||
|
||||
" Delete Words
|
||||
inoremap <C-BS> db
|
||||
inoremap <M-BS> d0
|
||||
inoremap <C-Del> dw
|
||||
inoremap <M-Del> d$
|
||||
nnoremap <C-BS> db
|
||||
nnoremap <M-BS> d0
|
||||
nnoremap <C-Del> dw
|
||||
nnoremap <M-Del> d$
|
||||
|
||||
" Select
|
||||
nnoremap <S-Left> vh
|
||||
inoremap <S-Left> <Esc>vh
|
||||
nnoremap <S-Right> vl
|
||||
inoremap <S-Right> <Esc>vl
|
||||
nnoremap <S-Up> vk
|
||||
vnoremap <S-Up> k
|
||||
inoremap <S-Up> <Esc>vk
|
||||
nnoremap <S-Down> vj
|
||||
vnoremap <S-Down> j
|
||||
inoremap <S-Down> <Esc>vj
|
||||
inoremap <S-Home> <Esc>v^
|
||||
inoremap <S-Home> <Esc>v^
|
||||
nnoremap <S-End> v$
|
||||
inoremap <S-End> <Esc>v^
|
||||
|
||||
" Save
|
||||
nnoremap <C-s> :w<CR>
|
||||
inoremap <C-s> <Esc>:w<CR>a
|
||||
vnoremap <C-s> <Esc>:w<CR>
|
||||
|
||||
" Quit
|
||||
nnoremap <C-q> :qa<CR>
|
||||
inoremap <C-q> <Esc>:qa<CR>
|
||||
|
||||
" Slower Scroll Page
|
||||
nnoremap <PageDown> <C-d><C-d>
|
||||
nnoremap <PageUp> <C-u><C-u>
|
||||
vnoremap <PageDown> <C-d>
|
||||
vnoremap <PageUp> <C-u>
|
||||
inoremap <PageDown> <C-o><C-d><C-o><C-d>
|
||||
inoremap <PageUp> <C-o><C-u><C-o><C-u>
|
||||
|
||||
" Slower Scroll Wheel
|
||||
nnoremap <ScrollWheelUp> <C-u>
|
||||
nnoremap <ScrollWheelDown> <C-d>
|
||||
vnoremap <ScrollWheelUp> k
|
||||
vnoremap <ScrollWheelDown> j
|
||||
inoremap <ScrollWheelUp> <C-o><C-u>
|
||||
inoremap <ScrollWheelDown> <C-o><C-d>
|
||||
|
||||
" Move Lines
|
||||
nnoremap <A-j> :m .+1<CR>==
|
||||
nnoremap <A-k> :m .-2<CR>==
|
||||
inoremap <A-j> <Esc>:m .+1<CR>==gi
|
||||
inoremap <A-k> <Esc>:m .-2<CR>==gi
|
||||
vnoremap <A-j> :m '>+1<CR>gv=gv
|
||||
vnoremap <A-k> :m '<-2<CR>gv=gv
|
||||
|
||||
|
||||
Reference in New Issue
Block a user