Compare commits

...

10 Commits

Author SHA1 Message Date
bretello a9a45864d2
README: fix CI badge 2024-04-06 21:24:46 +02:00
bretello 62c95b60d5
vim: disable ALE fix on save on git diffs 2024-04-06 21:24:45 +02:00
bretello c137ef0e0f
vim: increase history limits 2024-04-06 21:24:45 +02:00
bretello 3db7721edb
zsh: functions: cleanup tracing functions 2024-04-06 21:24:45 +02:00
bretello faf318c3d0
zsh: functions: add alarm function for quick alarms 2024-04-06 21:24:45 +02:00
bretello 1ee73be7f9
zsh: functions: get rid of ppath (use realpath instead) 2024-04-06 21:24:45 +02:00
bretello 8cdbefa3de
zsh: aliases: add C and P copy copy/paste 2024-04-06 21:24:45 +02:00
bretello 22023f667e
zsh: aliases: fix ssh1 alias (force new master, no persist) 2024-04-06 21:24:45 +02:00
bretello 114bbe758e
zsh: cleanup command lookup 2024-04-06 21:24:45 +02:00
bretello 7312c868b3
zsh: theme: avoid using functions where possible
includes fix for ohmyzsh's breaking change in ec1afe9d (async prompt)
2024-04-06 21:24:45 +02:00
8 changed files with 69 additions and 57 deletions

View File

@ -2,7 +2,7 @@
My own dotfiles. `zsh` configuration based on [antibody](https://github.com/getantibody/antibody) and [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh), `vim` configuration uses [vim-plug](https://github.com/junegunn/vim-plug), [ALE](https://github.com/dense-analysis/ale) and more.
[ci.decapod.one status](https://ci.decapod.one/api/badges/2/status.svg)
[!ci.decapod.one status](https://ci.decapod.one/api/badges/2/status.svg)
[zsh theme](docs/brethil-theme.png "zsh theme")
[vim theme](docs/vim.png "vim theme")

View File

@ -58,8 +58,8 @@ fi
## Stress one CPU core
alias stress='yes >> /dev/null'
# define ssh without controlmaster
alias ssh1="ssh -o ControlMaster=no"
# ssh forcing a new connection (no persistent)
alias ssh1="ssh -o ControlMaster=yes -o ControlPersist=no"
alias watcha='watch ' # note the space after watch. This makes watch work with aliases
@ -82,3 +82,7 @@ alias drp='dvc repro'
alias drps='dvc repro -s'
alias -g J="| jq "
# These two depend on oh-my-zsh's clipcopy/clippaste functions
alias -g C='| clipcopy'
alias -g P='clippaste'

View File

@ -18,19 +18,19 @@ antibody bundle < "$DOTFILES/antibody_plugins.txt"
source $DOTFILES/completion_style.zsh
source $DOTFILES/extras/fzf-tab-config.zsh
if command -vp fd >/dev/null; then
if [[ $+commands[fd] ]]; then
export FZF_CTRL_T_COMMAND='fd'
else
export FZF_CTRL_T_COMMAND='find'
fi
export FZF_CTRL_T_OPTS=" --preview-window=right,60% --preview \"bash -c 'if [[ -d \"{}\" ]]; then tree -C \"{}\"; else bat --style=plain --color=always \"{}\"; fi'\" --bind 'ctrl-/:change-preview-window(right,70%|down,40%,border-horizontal|hidden|right)'"
if [[ "$(command -v systemctl)" ]]; then
if [[ $+commands[systemctl] ]]; then
antibody bundle robbyrussell/oh-my-zsh path:plugins/systemd
fi
if [[ "$(command -v pacman)" ]]; then
if [[ $+commands[pacman] ]]; then
antibody bundle robbyrussell/oh-my-zsh path:plugins/archlinux
elif [[ "$(command -v apt-get)" ]]; then
elif [[ $+commands[apt-get] ]]; then
antibody bundle robbyrussell/oh-my-zsh path:plugins/debian
fi
@ -82,12 +82,8 @@ export ZSH_AUTOSUGGEST_COMPLETION_IGNORE='* \#*' # prevent completion for commen
# less options
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
else
cmd=batcat
fi
if [[ $+commands[bat] || $+commands[batcat] ]]; then
if [[ $+commands[bat] ]]; then cmd=bat else cmd=batcat fi
alias cat=$cmd
export PAGER=$cmd

View File

@ -44,13 +44,6 @@ function calc
awk "BEGIN { print $* }"
}
## Print full path of item in current directory
function ppath
{
echo "$PWD/$1"
}
function warning {
echo -e "${Yellow}Warning:$CLEAR $@" >&2
}
@ -76,6 +69,30 @@ function beeper
while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n -t1 && break; done;
}
# set an alarm in seconds, minutes, hours
function alarm {
if [[ -z $1 ]]; then
echo "Usage: alarm 5[s]|5m|1h"
return 1
fi
local t
if [[ $1 = *"m" ]]; then
t=$((${1/m/}*60))
extra="($1)"
elif [[ $1 = *"h" ]]; then
t=$((${1/h/}*3600))
extra="($1)"
elif [[ $1 = *"s" ]]; then
t=${1/s/}
else
t=$1
fi
echo "Setting a timer for $1 $extra"
sleep $t && beeper
}
## Simple http server for current directory (or path)
function httpserver

View File

@ -3,9 +3,10 @@
function start_tracing {
zmodload zsh/zprof
zmodload zsh/datetime
setopt PROMPT_SUBST
PS4+='+$EPOCHREALTIME %N:%i> '
logfile=$(mktemp zsh_profile.XXXXXXXX)
logfile=$(mktemp --tmpdir zsh_profile.XXXXXXXX)
echo "logging to $logfile"
exec 3>&2 2>$logfile
setopt XTRACE
@ -14,5 +15,8 @@ function start_tracing {
function stop_tracing {
unsetopt XTRACE
exec 2>&3 3>&-
zprof | tee zprof_out.log | vimscratch -
zprof | tee zprof_out.log | vim -c "set buftype=nofile" -
zmodload -u zsh/zprof
zmodload -u zsh/datetime
}

View File

@ -1,3 +1,5 @@
# vim:ft=zsh ts=2 sw=2 sts=2
local ret_status="%(?:%{$fg_bold[green]%}➜%{$reset_color%}:%{$fg[red]%}➜%{$reset_color%})"
local user="%(#:root@:)"
PROMPT='[%{$fg[red]%}${user}%M%{$reset_color%}][:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} '

View File

@ -18,10 +18,7 @@ function user_prompt(){
fi
}
function job_prompt() {
# Shows jobs number on an orange background if there are background jobs
echo "%(1j.%B%K{202}%F{220} %j %k%b.)"
}
local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)"
function shlvl_prompt() {
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
@ -32,14 +29,13 @@ function shlvl_prompt() {
fi
}
function path_prompt(){
# Shows last 3 items in path if there are more than 4
echo "[%F{green}%(4~:…/%3~:%~)%f]"
}
# TODO: add truncation using
# Shows last 3 items in path if there are more than 4
local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]'
# PREFIX/SUFFIX are added before/after `git_prompt_info`
ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_PREFIX=" %f%{$fg[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} |"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}"
@ -75,39 +71,24 @@ function virtualenv_info {
echo -n " $BOLD_PURPLE<$venv>$CLEAR "
}
function git_prompt() {
# prints git info if in a git repo
if ! git rev-parse --git-dir &>/dev/null; then
return
fi
echo " $(git_prompt_info) |$(git_prompt_status)$(git_remote_status)"
}
local git_prompt='$(git_prompt_info)$(git_prompt_status)$(git_remote_status)'
local return_code_RPS1='%(?..%B%F{88}-$?-%f%b)'
function return_code_RPS1() {
# red status code if last exit code is non-zero
echo "%(?..%B%F{88}-$?-%f%b)"
}
local success="%B%F{28} →%f%b"
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
local prompt_with_previous_return_status="%(?:$success:$failure) "
function prompt_with_previous_return_status() {
local success="%B%F{28} →%f%b"
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
echo "%(?:$success:$failure)"
}
function prompt_too_long(){
# prints a newline if more than $COLUMNS/2 characters have been printed
local newline=$'\n'
echo "%-$((COLUMNS/2))(l..${newline})"
}
# prints a newline if more than $COLUMNS/2 characters have been printed, see end of `man zshmisc`
local prompt_too_long='%-$((COLUMNS/2))(l..'$'\n'')'
## oh-my-zsh vi-mode plugins indicators:
export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background
PROMPT='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_prompt)$(shlvl_prompt)$(prompt_too_long)$(prompt_with_previous_return_status) '
# put it all together
PROMPT='$(virtualenv_info)$(user_prompt)'"${path_prompt}${git_prompt}${job_prompt}"'$(shlvl_prompt)'"${prompt_too_long}${prompt_with_previous_return_status}"
# Right prompt is just return code and time
RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)[%*]'
RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'

View File

@ -69,6 +69,10 @@ set foldminlines=3
" Timeout for combined keymaps (half a sec)
set timeoutlen=500
" keep history the last 1000 opened files, 200 commands and 50 search
" patterns. `h` persists bookmarks across sessions
set viminfo='1000,<200,s50,h
autocmd FileType qf,ll setlocal wrap "quickfix,loclist
autocmd FileType markdown setlocal wrap spell spelllang=it,en
autocmd FileType yaml,yml setlocal shiftwidth=2 softtabstop=2 expandtab
@ -83,6 +87,10 @@ syntax match jsonComment "\(/\*\)\|\(\*/\)"
hi def link jsonComment Comment
augroup dotgit_diffs
au BufRead .git/*.diff let b:ale_fix_on_save=0
augroup END
augroup dvc
au BufRead dvc.yaml let b:ale_fix_on_save=0
au BufRead *.dvc let b:ale_fix_on_save=0