mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-09-28 20:01:31 +02:00
Compare commits
No commits in common. "0c7d0ec24f28056f843f877d120482ee519648d5" and "481c81c68a822412590ef78d9e4d156249185f8a" have entirely different histories.
0c7d0ec24f
...
481c81c68a
|
@ -84,24 +84,23 @@ export ZSH_AUTOSUGGEST_COMPLETION_IGNORE='* \#*' # prevent completion for commen
|
||||||
export LESS='-xRF-j12' # -j12: displays 12 lines before search results with / and ?
|
export LESS='-xRF-j12' # -j12: displays 12 lines before search results with / and ?
|
||||||
if [[ "$(command -v bat)" || "$(command -v batcat)" ]]; then
|
if [[ "$(command -v bat)" || "$(command -v batcat)" ]]; then
|
||||||
if [[ "$(command -v bat)" ]]; then
|
if [[ "$(command -v bat)" ]]; then
|
||||||
cmd=bat
|
alias cat=bat
|
||||||
|
export PAGER=bat
|
||||||
else
|
else
|
||||||
cmd=batcat
|
alias cat=batcat
|
||||||
|
export PAGER=batcat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
alias cat=$cmd
|
|
||||||
export PAGER=$cmd
|
|
||||||
export BAT_PAGER="less $LESS"
|
|
||||||
|
|
||||||
if [[ -n $THEME_PREFER_LIGHT ]]; then
|
if [[ -n $THEME_PREFER_LIGHT ]]; then
|
||||||
export BAT_THEME="gruvbox-light"
|
export BAT_THEME="gruvbox-light"
|
||||||
else
|
else
|
||||||
export BAT_THEME="gruvbox-dark"
|
export BAT_THEME="gruvbox-dark"
|
||||||
fi
|
fi
|
||||||
|
export BAT_PAGER="less $LESS"
|
||||||
|
export PAGER=bat
|
||||||
|
|
||||||
## this breaks symlink testing with [ -h ], best not to activate it
|
## this breaks symlink testing with [ -h ], best not to activate it
|
||||||
# alias -g -- -h='-h 2>&1 | bat --language=help --style=plain'
|
# alias -g -- -h='-h 2>&1 | bat --language=help --style=plain'
|
||||||
alias bathelp="$cmd --language=help --style=plain"
|
alias bathelp='bat --language=help --style=plain'
|
||||||
alias -g -- --help='--help 2>&1 | bathelp '
|
alias -g -- --help='--help 2>&1 | bathelp '
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
31
colors.zsh
31
colors.zsh
|
@ -94,34 +94,3 @@ LIGHTCYAN="\e[36m"; LIGHTRED="\033[31m"; LIGHTPURPLE="\033[35m";
|
||||||
YELLOW="\e[33m"; WHITE="\033[37m"
|
YELLOW="\e[33m"; WHITE="\033[37m"
|
||||||
BACKGROUND_BLACK="\e[40"; BACKGROUND_RED="\033[41";
|
BACKGROUND_BLACK="\e[40"; BACKGROUND_RED="\033[41";
|
||||||
BACKGROUND_GREEN="\e[42"; BACKGROUND_YELLOW="\033[43m"
|
BACKGROUND_GREEN="\e[42"; BACKGROUND_YELLOW="\033[43m"
|
||||||
|
|
||||||
|
|
||||||
## Color string with given color. Usage: `color $NAME "string"`, available colors below
|
|
||||||
function color
|
|
||||||
{
|
|
||||||
local color=$1
|
|
||||||
shift 1
|
|
||||||
echo -e "${color}$@${CLEAR}"
|
|
||||||
}
|
|
||||||
|
|
||||||
## These functions return a colored version of the input string. Usage: red "string"
|
|
||||||
function red
|
|
||||||
{
|
|
||||||
echo -e "$Red$@$CLEAR"
|
|
||||||
}
|
|
||||||
function green
|
|
||||||
{
|
|
||||||
echo -e "$Green$@$CLEAR"
|
|
||||||
}
|
|
||||||
function yellow
|
|
||||||
{
|
|
||||||
echo -e "$Yellow$@$CLEAR"
|
|
||||||
}
|
|
||||||
function blue
|
|
||||||
{
|
|
||||||
echo -e "$Blue$@$CLEAR"
|
|
||||||
}
|
|
||||||
function bold
|
|
||||||
{
|
|
||||||
echo -e "$BOLD$@$CLEAR"
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
function warning {
|
||||||
|
echo -e "$(color $YELLOW Warning:) $@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
function error {
|
||||||
|
echo -e "$(color $RED Error:) $@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
function info {
|
||||||
|
echo -e "$(color $GREEN Info:) $@"
|
||||||
|
}
|
||||||
|
|
||||||
function switch-asciinema-user
|
function switch-asciinema-user
|
||||||
{
|
{
|
||||||
local conf_dir="$HOME/.config/asciinema"
|
local conf_dir="$HOME/.config/asciinema"
|
||||||
|
@ -22,22 +34,22 @@ function switch-asciinema-user
|
||||||
fi
|
fi
|
||||||
new_id=$(echo $ids| fzf --height=$(($(wc -l <<< $ids)+2)) ${query} )
|
new_id=$(echo $ids| fzf --height=$(($(wc -l <<< $ids)+2)) ${query} )
|
||||||
if [[ -z $new_id ]]; then
|
if [[ -z $new_id ]]; then
|
||||||
yellow "Keeping curent id ($(color $UNDERLINE ${current_id}))"
|
warning "Keeping curent id ($(color $UNDERLINE ${current_id}))"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$new_id" == "$current_id" ]]; then
|
if [[ "$new_id" == "$current_id" ]]; then
|
||||||
yellow "id $new_id is already set."
|
warning "id $new_id is already set."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local id_file="${conf_dir}/${new_id}"
|
local id_file="${conf_dir}/${new_id}"
|
||||||
if [[ ! -f ${id_file} ]]; then
|
if [[ ! -f ${id_file} ]]; then
|
||||||
red "${id_file} does not exist"
|
error "${id_file} does not exist"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sf "${id_file}" "${conf_dir}/install-id" && \
|
ln -sf "${id_file}" "${conf_dir}/install-id" && \
|
||||||
green "Set \"$new_id\"." || \
|
info "Set \"$new_id\"." || \
|
||||||
red "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
|
error "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,19 +50,32 @@ function ppath
|
||||||
echo "$PWD/$1"
|
echo "$PWD/$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Color string with given color. Usage: `color $NAME "string"`, available colors in `colors.sh`
|
||||||
function warning {
|
function color
|
||||||
echo -e "${Yellow}Warning:$CLEAR $@" >&2
|
{
|
||||||
|
local color=$1
|
||||||
|
shift 1
|
||||||
|
echo -e "${color}$@${CLEAR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function error {
|
|
||||||
echo -e "${Red}Error:$CLEAR $@" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
function info {
|
## These functions return a colored version of the input string. Usage: red "string"
|
||||||
echo -e "${Green}Info:$CLEAR $@"
|
function red
|
||||||
|
{
|
||||||
|
echo -e "$Red$@$CLEAR"
|
||||||
|
}
|
||||||
|
function green
|
||||||
|
{
|
||||||
|
echo -e "$Green$@$CLEAR"
|
||||||
|
}
|
||||||
|
function blue
|
||||||
|
{
|
||||||
|
echo -e "$Blue$@$CLEAR"
|
||||||
|
}
|
||||||
|
function bold
|
||||||
|
{
|
||||||
|
echo -e "$BOLD$@$CLEAR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## Flashes the screen until user presses a key
|
## Flashes the screen until user presses a key
|
||||||
function flasher
|
function flasher
|
||||||
|
@ -202,7 +215,9 @@ fvim() {
|
||||||
|
|
||||||
# retry command until it succeeds (waiting one second or $RETRY_INTERVAL)
|
# retry command until it succeeds (waiting one second or $RETRY_INTERVAL)
|
||||||
function retry() {
|
function retry() {
|
||||||
until $@; do sleep ${RETRY_INTERVAL:-1}; done
|
local _retry_interval
|
||||||
|
if [[ -z "$RETRY_INTERVAL" ]]; then _retry_interval=1; else _retry_interval=$RETRY_INTERVAL; fi
|
||||||
|
until $@; do sleep $_retry_interval; done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,43 +291,15 @@ function mangrep() {
|
||||||
|
|
||||||
# watches the given file and executes the given action whenever the file is changed. Usage: watch_file <file> <command>
|
# watches the given file and executes the given action whenever the file is changed. Usage: watch_file <file> <command>
|
||||||
function watch_file() {
|
function watch_file() {
|
||||||
if ! which inotifywait 2>&1 &>/dev/null ; then echo "$0 requires inotifywait"; return 1; fi
|
if ! which inotifywait &>/dev/null ; then echo "$0 requires inotifywait"; return 1; fi
|
||||||
|
[[ -z "$1" ]] && "Usage: $0 <file> <action>" && return 1
|
||||||
[[ -z "$1" ]] && echo "Usage: $0 <file> <action>" && return 1
|
local file
|
||||||
local file=$1
|
file="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
[[ -z "$@" ]] && echo "Usage: $0 <file> <action>" && return 1
|
[[ -z "$@" ]] && "Usage: $0 <file> <action>" && return 1
|
||||||
|
|
||||||
local action="$@"
|
local action
|
||||||
local _bg_job_pid
|
action="$@"
|
||||||
|
while inotifywait -e close_write "$file"; do zsh -c "$action"; done
|
||||||
local TRAPINT(){
|
|
||||||
|
|
||||||
if [[ -n ${_bg_job_pid} ]]; then
|
|
||||||
kill -9 ${_bg_job_pid}
|
|
||||||
fi
|
|
||||||
yellow '\nQuitting.'
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
set +m # disable job control messages
|
|
||||||
while true; do
|
|
||||||
zsh -c "$action" &
|
|
||||||
_bg_job_pid=$!
|
|
||||||
disown
|
|
||||||
echo -e "$Cyan ==> Running \"$action\" with pid=${_bg_job_pid}$CLEAR"
|
|
||||||
|
|
||||||
# block until the file has been written to
|
|
||||||
inotifywait -e close_write "$file" &>/dev/null
|
|
||||||
|
|
||||||
# the job might have failed, ignore errors
|
|
||||||
kill -9 ${_bg_job_pid} &>/dev/null || true
|
|
||||||
done
|
|
||||||
} always {
|
|
||||||
# remove ctrl-c trap
|
|
||||||
unset -f TRAPINT
|
|
||||||
set -m # restore job control messages
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,12 +129,13 @@ command! -nargs=1 -complete=command -bar -range Redir silent call Redir(<q-args>
|
||||||
function! Man(cmd)
|
function! Man(cmd)
|
||||||
vnew
|
vnew
|
||||||
let w:scratch=1
|
let w:scratch=1
|
||||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile filetype=man nonumber norelativenumber
|
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile filetype=man
|
||||||
let output = system('env COLUMNS=80 man ' . a:cmd)
|
setlocal nonumber norelativenumber
|
||||||
|
let output = system('man ' . a:cmd)
|
||||||
call setline(1, split(output, '\n'))
|
call setline(1, split(output, '\n'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -nargs=1 -complete=shellcmd Vert Man silent call Man(<q-args>)
|
command! -nargs=1 -complete=shellcmd Man silent call Man(<q-args>)
|
||||||
|
|
||||||
" Execute the given command and print it in a scratch buffer
|
" Execute the given command and print it in a scratch buffer
|
||||||
function! Cmd(cmd)
|
function! Cmd(cmd)
|
||||||
|
|
|
@ -46,9 +46,9 @@ nmap <leader>ll :botright lope<CR>
|
||||||
nmap <leader>cx :hide<CR>
|
nmap <leader>cx :hide<CR>
|
||||||
nmap <leader>co ggVGy:tabnew<CR>:set syntax=qf<CR>pgg
|
nmap <leader>co ggVGy:tabnew<CR>:set syntax=qf<CR>pgg
|
||||||
" next cope error
|
" next cope error
|
||||||
map <leader>N :cnext<CR>
|
map <leader>cn :cn<CR>
|
||||||
" previous cope error
|
" previous cope error
|
||||||
map <leader>P :cprevious<CR>
|
map <leader>cp :cp<CR>
|
||||||
|
|
||||||
"disable highlighting for current word
|
"disable highlighting for current word
|
||||||
map <silent> <leader><CR> :noh<CR>
|
map <silent> <leader><CR> :noh<CR>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user