Compare commits

...

9 Commits

Author SHA1 Message Date
bretello c41a91e784
vim: add <Leader>] and <Leader>[ to move between definitions
`<Leader>[` moves to the start of the previous method/function/class
definition, `<Leader>]` to the start of the next
2023-11-22 12:52:22 +01:00
bretello a20bffdf67
zsh: python: cleanup mkvenv 2023-11-11 23:33:50 +01:00
bretello 1537ddcc64
zsh: python: add -f flag to mkvenv
- improve mkvenv with getopts option parsing
- add -f flag to force recreation of venv

Usage:
```bash
mkvenv [-sf] [venv_name]
```
2023-11-11 18:54:40 +01:00
bretello aaea49ecf8 aliases: add J global alias for `| jq` 2023-10-25 11:48:03 +02:00
bretello 41eb8f1a5f zsh: vimscratch: add filetype arg
Allows setting filetype for vimscratch command.

Usage: `<command> | vimscratch [filetype]`.

For example:

```bash
curl https://myip.wtf/json | vimscratch json
```
Will open the output of the curl command as a json
temporary file in vim.
2023-10-25 11:45:54 +02:00
bretello f4e960be35 vim: lower timeout for combined keymaps 2023-10-25 11:44:33 +02:00
bretello 58201b2ab7 zsh: cleanup git functions 2023-10-25 11:43:44 +02:00
bretello 4d9462239f zsh: move git fuzzy log to gitconfig (usage: `git flog`) 2023-10-25 11:43:16 +02:00
bretello c329308759 zsh: avoid printing command name in completion wrapper 2023-10-25 11:34:36 +02:00
8 changed files with 70 additions and 23 deletions

View File

@ -79,3 +79,5 @@ alias dst='dvc status'
alias dstc='dvc status --cloud'
alias drp='dvc repro'
alias drps='dvc repro -s'
alias -g J="| jq "

View File

@ -34,15 +34,8 @@ function git-sort-branch-by-usage(){
function git-switch-recent-branch(){
git switch $1
}
# compdef git-sort-branch-by-usage git-switch-recent-branch
compdef "__git_completion_wrapper __git_recent_branches" git-switch-recent-branch
# Runs git log with fzf with preview
function fgitlog() {
git showtool $(git log --oneline $@ | fzf --multi --preview 'git -p show --color=always {+1}' --preview-window=right,60% | awk '{print $1}')
}
compdef _git fgitlog=git-log
function git-commit-show() {
git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" $@ |
fzf --ansi --no-sort --reverse --tiebreak=index --preview \
@ -87,18 +80,26 @@ function gco() {
if [[ "$#" -ge 1 ]]; then
g checkout $@
elif [[ "$#" -eq 0 ]]; then
g checkout $(gb | fzf)
local selected
selected=$(git branch --format "%(refname)" | cut -d / -f 3- | fzf)
if [[ -n $selected ]]; then
git checkout "$selected"
else
echo "Nothing selected"
fi
fi
}
compdef "__git_completion_wrapper _git-checkout" gco
_disable_alias gcor
function gcor() {
if [[ "$#" -ge 1 ]]; then
g checkout $@
git checkout $@
elif [[ "$#" -eq 0 ]]; then
g checkout --track $(gbr | fzf)
git checkout --track $(gbr | fzf)
fi
}
@ -116,9 +117,9 @@ compdef "__git_completion_wrapper __git_recent_branches" gbd
_disable_alias gbD
function gbD() {
if [[ "$#" -ge 1 ]]; then
g branch -D $@
git branch -D $@
elif [[ "$#" -eq 0 ]]; then
g branch -D $(gb | fzf -m)
git branch -D $(git branch | fzf -m)
fi
}
compdef "__git_completion_wrapper __git_recent_branches" gbD

View File

@ -224,7 +224,7 @@ __completion_wrapper(){
# completion functions
local _completion_function=$1
local _completion_base=$2
if ! command -v $_completion_function; then
if ! command -v $_completion_function &>/dev/null; then
$_completion_base
fi
$_completion_function

View File

@ -1,25 +1,52 @@
mkvenv(){
local source_venv
if [[ $1 == "-s" ]]; then
source_venv=y
local source_venv force_create venv_name
while getopts "sf" opt; do
case $opt in
s|source) source_venv=y ;;
f|force) force_create=y ;;
*) echo "Unknown option: $opt"; return 1 ;;
esac
done
shift $(($OPTIND-1))
if [[ -n $1 ]]; then
venv_name=$1
shift
else
venv_name=.venv
fi
# any arguments are passed on to the `venv` module as flags/arguments
if [[ -e .venv ]]; then
echo "$(color $RED Error:) $(color $BOLD .venv) already exists." >&2
# any other arguments are passed on to the `venv` module as flags/arguments
if [[ -e ${venv_name} ]]; then
if [[ -n ${force_create} ]]; then
if [[ -n $VIRTUAL_ENV ]]; then # deactivate venv if enabled
deactivate && warning "Deactivated existing virtualenv" || red "Could not run deactivate";
fi
rm -rf ${venv_name} && warning "Deleted existing virtualenv."
else
error "$(color $BOLD .venv) already exists. Run with -f to recreate it." >&2
return 1
fi
fi
info "Creating virtualenv ${venv_name}... "
if ! python -m virtualenv $@ ${venv_name} ; then
error "Failed to create virtualenv. Is virtualenv installed? Try:\n $ pip install virtualenv"
return 1
fi
echo -n "Creating venv..." && python -m virtualenv $@ .venv || echo -e "Failed to create virtualenv. Is virtualenv installed? Try:\n $ pip install virtualenv"
if [[ -z ${source_venv} ]]; then
echo -n " done. Enable? [Y/n]"
echo -n " done. Enable? [Y/n] "
read source_venv
else
echo ""
fi
if [[ $source_venv != "n" ]]; then
source .venv/bin/activate && echo -e "$(color $BOLD Enabled!) 🐍 $(color $BOLD$PURPLE $(python --version | cut -d " " -f2 )) ($(color $BOLD$GREEN $(pip --version | cut -d " " -f -2)))"
source ${venv_name}/bin/activate && \
echo -e "$(color $BOLD Enabled!) 🐍 $(color $BOLD$PURPLE $(python --version | cut -d " " -f2 )) ($(color $BOLD$GREEN $(pip --version | cut -d " " -f -2)))"
fi
}

View File

@ -6,5 +6,13 @@ vimscratch() {
if [ ! -t 0 ] ; then
stdin_arg="-"
fi
vim -c "set buftype=nofile" $@ $stdin_arg
set +x
if [[ -n "$1" ]]; then
filetype=$1
shift
vim -c "set buftype=nofile" -c "set filetype=$filetype" $@ $stdin_arg
else
vim -c "set buftype=nofile" $filetype_arg $@ $stdin_arg
fi
}

View File

@ -35,3 +35,4 @@ abbrevcommit = true
[alias]
showtool = "!showci () { rev=${1:-HEAD}; git difftool $rev~1 $rev; }; showci $1"
mylog = "log --pretty='format:👉 %C(yellow)commit: %h%C(auto)%d %Creset%nAuthor: %C(auto,cyan)%>(12)%an (%aE)%n%C(reset)Date: %C(auto,green)%ar%Creset%nContent: %s'"
flog = "!flog() { git log --oneline $@ | fzf --multi --preview 'git -p show --color=always {+1}' --preview-window=right,60% | awk '{print $1}'; }; flog"

View File

@ -32,6 +32,11 @@ nmap <C-W>n :tabnext<CR>
nmap <C-W>p :tabprev<CR>
nmap <C-W>N :tabnew<CR>
" move betweween methods, centering the method on each movement
" [m moves to the start of the previous method, ]m to the end
map <Leader>] ]mzz
map <Leader>[ [mzz
" open quickfix
nmap <leader>cc :botright cope<CR>
" open loclist

View File

@ -66,6 +66,9 @@ set cursorline
" Minimum fold size
set foldminlines=3
" Timeout for combined keymaps (half a sec)
set timeoutlen=500
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