mirror of https://git.decapod.one/brethil/dotfiles
Compare commits
6 Commits
481c81c68a
...
0c7d0ec24f
Author | SHA1 | Date |
---|---|---|
bretello | 0c7d0ec24f | |
bretello | b05fde87c2 | |
bretello | 04bfe043ab | |
bretello | 35575755ef | |
bretello | 10c79f1bad | |
bretello | 25037bde1f |
|
@ -84,23 +84,24 @@ export ZSH_AUTOSUGGEST_COMPLETION_IGNORE='* \#*' # prevent completion for commen
|
|||
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)" ]]; then
|
||||
alias cat=bat
|
||||
export PAGER=bat
|
||||
cmd=bat
|
||||
else
|
||||
alias cat=batcat
|
||||
export PAGER=batcat
|
||||
cmd=batcat
|
||||
fi
|
||||
|
||||
alias cat=$cmd
|
||||
export PAGER=$cmd
|
||||
export BAT_PAGER="less $LESS"
|
||||
|
||||
if [[ -n $THEME_PREFER_LIGHT ]]; then
|
||||
export BAT_THEME="gruvbox-light"
|
||||
else
|
||||
export BAT_THEME="gruvbox-dark"
|
||||
fi
|
||||
export BAT_PAGER="less $LESS"
|
||||
export PAGER=bat
|
||||
|
||||
## this breaks symlink testing with [ -h ], best not to activate it
|
||||
# alias -g -- -h='-h 2>&1 | bat --language=help --style=plain'
|
||||
alias bathelp='bat --language=help --style=plain'
|
||||
alias bathelp="$cmd --language=help --style=plain"
|
||||
alias -g -- --help='--help 2>&1 | bathelp '
|
||||
fi
|
||||
|
||||
|
|
31
colors.zsh
31
colors.zsh
|
@ -94,3 +94,34 @@ LIGHTCYAN="\e[36m"; LIGHTRED="\033[31m"; LIGHTPURPLE="\033[35m";
|
|||
YELLOW="\e[33m"; WHITE="\033[37m"
|
||||
BACKGROUND_BLACK="\e[40"; BACKGROUND_RED="\033[41";
|
||||
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,15 +1,3 @@
|
|||
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
|
||||
{
|
||||
local conf_dir="$HOME/.config/asciinema"
|
||||
|
@ -34,22 +22,22 @@ function switch-asciinema-user
|
|||
fi
|
||||
new_id=$(echo $ids| fzf --height=$(($(wc -l <<< $ids)+2)) ${query} )
|
||||
if [[ -z $new_id ]]; then
|
||||
warning "Keeping curent id ($(color $UNDERLINE ${current_id}))"
|
||||
yellow "Keeping curent id ($(color $UNDERLINE ${current_id}))"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$new_id" == "$current_id" ]]; then
|
||||
warning "id $new_id is already set."
|
||||
yellow "id $new_id is already set."
|
||||
return
|
||||
fi
|
||||
|
||||
local id_file="${conf_dir}/${new_id}"
|
||||
if [[ ! -f ${id_file} ]]; then
|
||||
error "${id_file} does not exist"
|
||||
red "${id_file} does not exist"
|
||||
return
|
||||
fi
|
||||
|
||||
ln -sf "${id_file}" "${conf_dir}/install-id" && \
|
||||
info "Set \"$new_id\"." || \
|
||||
error "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
|
||||
green "Set \"$new_id\"." || \
|
||||
red "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
|
||||
}
|
||||
|
|
|
@ -50,33 +50,20 @@ function ppath
|
|||
echo "$PWD/$1"
|
||||
}
|
||||
|
||||
## Color string with given color. Usage: `color $NAME "string"`, available colors in `colors.sh`
|
||||
function color
|
||||
{
|
||||
local color=$1
|
||||
shift 1
|
||||
echo -e "${color}$@${CLEAR}"
|
||||
|
||||
function warning {
|
||||
echo -e "${Yellow}Warning:$CLEAR $@" >&2
|
||||
}
|
||||
|
||||
function error {
|
||||
echo -e "${Red}Error:$CLEAR $@" >&2
|
||||
}
|
||||
|
||||
## 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 blue
|
||||
{
|
||||
echo -e "$Blue$@$CLEAR"
|
||||
}
|
||||
function bold
|
||||
{
|
||||
echo -e "$BOLD$@$CLEAR"
|
||||
function info {
|
||||
echo -e "${Green}Info:$CLEAR $@"
|
||||
}
|
||||
|
||||
|
||||
## Flashes the screen until user presses a key
|
||||
function flasher
|
||||
{
|
||||
|
@ -215,9 +202,7 @@ fvim() {
|
|||
|
||||
# retry command until it succeeds (waiting one second or $RETRY_INTERVAL)
|
||||
function retry() {
|
||||
local _retry_interval
|
||||
if [[ -z "$RETRY_INTERVAL" ]]; then _retry_interval=1; else _retry_interval=$RETRY_INTERVAL; fi
|
||||
until $@; do sleep $_retry_interval; done
|
||||
until $@; do sleep ${RETRY_INTERVAL:-1}; done
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,15 +276,43 @@ function mangrep() {
|
|||
|
||||
# watches the given file and executes the given action whenever the file is changed. Usage: watch_file <file> <command>
|
||||
function watch_file() {
|
||||
if ! which inotifywait &>/dev/null ; then echo "$0 requires inotifywait"; return 1; fi
|
||||
[[ -z "$1" ]] && "Usage: $0 <file> <action>" && return 1
|
||||
local file
|
||||
file="$1"
|
||||
if ! which inotifywait 2>&1 &>/dev/null ; then echo "$0 requires inotifywait"; return 1; fi
|
||||
|
||||
[[ -z "$1" ]] && echo "Usage: $0 <file> <action>" && return 1
|
||||
local file=$1
|
||||
shift
|
||||
|
||||
[[ -z "$@" ]] && "Usage: $0 <file> <action>" && return 1
|
||||
[[ -z "$@" ]] && echo "Usage: $0 <file> <action>" && return 1
|
||||
|
||||
local action
|
||||
action="$@"
|
||||
while inotifywait -e close_write "$file"; do zsh -c "$action"; done
|
||||
local action="$@"
|
||||
local _bg_job_pid
|
||||
|
||||
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,13 +129,12 @@ command! -nargs=1 -complete=command -bar -range Redir silent call Redir(<q-args>
|
|||
function! Man(cmd)
|
||||
vnew
|
||||
let w:scratch=1
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile filetype=man
|
||||
setlocal nonumber norelativenumber
|
||||
let output = system('man ' . a:cmd)
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile filetype=man nonumber norelativenumber
|
||||
let output = system('env COLUMNS=80 man ' . a:cmd)
|
||||
call setline(1, split(output, '\n'))
|
||||
endfunction
|
||||
|
||||
command! -nargs=1 -complete=shellcmd Man silent call Man(<q-args>)
|
||||
command! -nargs=1 -complete=shellcmd Vert Man silent call Man(<q-args>)
|
||||
|
||||
" Execute the given command and print it in a scratch buffer
|
||||
function! Cmd(cmd)
|
||||
|
|
|
@ -46,9 +46,9 @@ nmap <leader>ll :botright lope<CR>
|
|||
nmap <leader>cx :hide<CR>
|
||||
nmap <leader>co ggVGy:tabnew<CR>:set syntax=qf<CR>pgg
|
||||
" next cope error
|
||||
map <leader>cn :cn<CR>
|
||||
map <leader>N :cnext<CR>
|
||||
" previous cope error
|
||||
map <leader>cp :cp<CR>
|
||||
map <leader>P :cprevious<CR>
|
||||
|
||||
"disable highlighting for current word
|
||||
map <silent> <leader><CR> :noh<CR>
|
||||
|
|
Loading…
Reference in New Issue