Compare commits

..

No commits in common. "0c7d0ec24f28056f843f877d120482ee519648d5" and "481c81c68a822412590ef78d9e4d156249185f8a" have entirely different histories.

6 changed files with 63 additions and 95 deletions

View File

@ -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 ?
if [[ "$(command -v bat)" || "$(command -v batcat)" ]]; then
if [[ "$(command -v bat)" ]]; then
cmd=bat
alias cat=bat
export PAGER=bat
else
cmd=batcat
alias cat=batcat
export PAGER=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="$cmd --language=help --style=plain"
alias bathelp='bat --language=help --style=plain'
alias -g -- --help='--help 2>&1 | bathelp '
fi

View File

@ -94,34 +94,3 @@ 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"
}

View File

@ -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
{
local conf_dir="$HOME/.config/asciinema"
@ -22,22 +34,22 @@ function switch-asciinema-user
fi
new_id=$(echo $ids| fzf --height=$(($(wc -l <<< $ids)+2)) ${query} )
if [[ -z $new_id ]]; then
yellow "Keeping curent id ($(color $UNDERLINE ${current_id}))"
warning "Keeping curent id ($(color $UNDERLINE ${current_id}))"
return
fi
if [[ "$new_id" == "$current_id" ]]; then
yellow "id $new_id is already set."
warning "id $new_id is already set."
return
fi
local id_file="${conf_dir}/${new_id}"
if [[ ! -f ${id_file} ]]; then
red "${id_file} does not exist"
error "${id_file} does not exist"
return
fi
ln -sf "${id_file}" "${conf_dir}/install-id" && \
green "Set \"$new_id\"." || \
red "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
info "Set \"$new_id\"." || \
error "Could not set id \"$new_id\". (run with -l for a list of available profiles)"
}

View File

@ -50,19 +50,32 @@ function ppath
echo "$PWD/$1"
}
function warning {
echo -e "${Yellow}Warning:$CLEAR $@" >&2
## 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 error {
echo -e "${Red}Error:$CLEAR $@" >&2
}
function info {
echo -e "${Green}Info:$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 blue
{
echo -e "$Blue$@$CLEAR"
}
function bold
{
echo -e "$BOLD$@$CLEAR"
}
## Flashes the screen until user presses a key
function flasher
@ -202,7 +215,9 @@ fvim() {
# retry command until it succeeds (waiting one second or $RETRY_INTERVAL)
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>
function watch_file() {
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
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"
shift
[[ -z "$@" ]] && echo "Usage: $0 <file> <action>" && return 1
[[ -z "$@" ]] && "Usage: $0 <file> <action>" && return 1
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
}
local action
action="$@"
while inotifywait -e close_write "$file"; do zsh -c "$action"; done
}

View File

@ -129,12 +129,13 @@ 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 nonumber norelativenumber
let output = system('env COLUMNS=80 man ' . a:cmd)
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile filetype=man
setlocal nonumber norelativenumber
let output = system('man ' . a:cmd)
call setline(1, split(output, '\n'))
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
function! Cmd(cmd)

View File

@ -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>N :cnext<CR>
map <leader>cn :cn<CR>
" previous cope error
map <leader>P :cprevious<CR>
map <leader>cp :cp<CR>
"disable highlighting for current word
map <silent> <leader><CR> :noh<CR>