initial commit
This commit is contained in:
parent
1184af4305
commit
cd62c10fd4
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
kitty +icat --clear --silent --transfer-mode file
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
# Basic vars
|
||||
set ratios 1:2:4
|
||||
set shellopts '-eu'
|
||||
set ifs "\n"
|
||||
set scrolloff 10
|
||||
set icons
|
||||
set wrapscroll
|
||||
set period 1
|
||||
set findlen 2
|
||||
set previewer ~/.config/lf/preview
|
||||
set cleaner ~/.config/lf/clean
|
||||
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[33m%f\033[35m]\033[0m"
|
||||
|
||||
cmd open ${{
|
||||
case $(file --mime-type "$(readlink -f $f)" -b) in
|
||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;;
|
||||
image/vnd.djvu|application/pdf|application/octet-stream|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
||||
text/*|application/json|inode/x-empty) $EDITOR $fx;;
|
||||
image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
|
||||
image/svg+xml) display -- $f ;;
|
||||
image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|tif\|ico\)\(_large\)*$" |
|
||||
setsid -f sxiv -aio 2>/dev/null | while read -r file; do
|
||||
[ -z "$file" ] && continue
|
||||
lf -remote "send select \"$file\""
|
||||
lf -remote "send toggle"
|
||||
done &
|
||||
;;
|
||||
audio/*) mpv --audio-display=no $f ;;
|
||||
video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
|
||||
application/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
||||
application/pgp-encrypted) $EDITOR $fx ;;
|
||||
*) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')"
|
||||
|
||||
cmd extract ${{
|
||||
clear; tput cup $(($(tput lines)/3)); tput bold
|
||||
set -f
|
||||
printf "%s\n\t" "$fx"
|
||||
printf "extract?[y/N]"
|
||||
read ans
|
||||
[ $ans = "y" ] && aunpack $fx
|
||||
}}
|
||||
|
||||
cmd delete ${{
|
||||
clear; tput cup $(($(tput lines)/3)); tput bold
|
||||
set -f
|
||||
printf "%s\n\t" "$fx"
|
||||
printf "delete?[y/N]"
|
||||
read ans
|
||||
[ $ans = "y" ] && rm -rf -- $fx
|
||||
}}
|
||||
|
||||
cmd trash ${{
|
||||
clear; tput cup $(($(tput lines)/3)); tput bold
|
||||
set -f
|
||||
printf "%s\n\t" "$fx"
|
||||
printf "trash?[y/N]"
|
||||
read ans
|
||||
[ $ans = "y" ] && trash-put $fx
|
||||
}}
|
||||
|
||||
cmd rsyncto ${{
|
||||
clear; tput cup $(($(tput lines)/3)); tput bold
|
||||
set -f
|
||||
clear; echo "rsync to where?"
|
||||
read dest
|
||||
for x in $fx; do
|
||||
eval rsync -aAXHv \"$x\" \"$dest\"
|
||||
done &&
|
||||
notify-send "File(s) rsynced." "File(s) copies to $dest."
|
||||
}}
|
||||
|
||||
# y (select for copy) and P to paste soft-link
|
||||
# d (select for cut) and P to paste hard-link
|
||||
cmd link %{{
|
||||
set -- $(cat ~/.local/share/lf/files)
|
||||
mode="$1"
|
||||
shift
|
||||
if [ "$#" -lt 1 ]; then
|
||||
lf -remote "send $id echo no files to link"
|
||||
exit 0
|
||||
fi
|
||||
case "$mode" in
|
||||
# symbolically copy mode is indicating a soft link
|
||||
copy) ln -sr -t . -- "$@";;
|
||||
# while a move mode is indicating a hard link
|
||||
move) ln -t . -- "$@";;
|
||||
esac
|
||||
rm ~/.local/share/lf/files
|
||||
lf -remote "send clear"
|
||||
}}
|
||||
|
||||
cmd setbg "$1"
|
||||
cmd bulkrename $vidir
|
||||
|
||||
cmd git_branch ${{
|
||||
git branch | fzf | xargs git checkout
|
||||
pwd_shell=$(pwd)
|
||||
lf -remote "send $id updir"
|
||||
lf -remote "send $id cd \"$pwd_shell\""
|
||||
}}
|
||||
|
||||
|
||||
|
||||
cmd on-cd &{{
|
||||
DIR=$(echo $PWD | sed "s|$HOME|~|")
|
||||
printf "\033]0; $DIR\007" > /dev/tty
|
||||
}}
|
||||
on-cd
|
||||
|
||||
cmd on-quit ${{
|
||||
DIR=$(echo $PWD | sed "s|$HOME|~|")
|
||||
printf "\033]0; $DIR\007" > /dev/tty
|
||||
}}
|
||||
|
||||
cmd paste &{{
|
||||
set -- $(cat ~/.local/share/lf/files)
|
||||
mode="$1"
|
||||
shift
|
||||
case "$mode" in
|
||||
copy)
|
||||
rsync -av --ignore-existing --progress -- "$@" . |
|
||||
stdbuf -i0 -o0 -e0 tr '\r' '\n' |
|
||||
while IFS= read -r line; do
|
||||
lf -remote "send $id echo $line"
|
||||
done
|
||||
;;
|
||||
move) mv -n -- "$@" .;;
|
||||
esac
|
||||
rm ~/.local/share/lf/files
|
||||
lf -remote "send clear"
|
||||
}}
|
||||
|
||||
cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c
|
||||
|
||||
# Bindings
|
||||
map <c-f> $lf -remote "send $id select '$(fzf)'"
|
||||
map J $dir=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf) && lf -remote "send $id cd $(eval echo $dir)"
|
||||
map D trash
|
||||
map <c-d> delete
|
||||
map E extract
|
||||
map R rsyncto
|
||||
map P link
|
||||
map S share
|
||||
map <c-g> $lazygit
|
||||
map V push :!$EDITOR<space>
|
||||
map <c-n> push :mkdir<space>
|
||||
map <c-r> reload
|
||||
map <c-s> set hidden!
|
||||
map <enter> shell
|
||||
map x $$f
|
||||
map X !$f
|
||||
map o &mimeopen $f
|
||||
map O $mimeopen --ask $f
|
||||
|
||||
map A rename # at the very end
|
||||
map a push A<c-a> # at the very beginning
|
||||
map I push A<a-b> # after extension
|
||||
map i push A<a-b><a-b><a-f> # before extension
|
||||
map c push A<c-u> # new rename
|
||||
map B bulkrename
|
||||
|
||||
# source directory shortcuts
|
||||
source "~/.config/lf/shortcutrc"
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env bash
|
||||
image() {
|
||||
file=$1
|
||||
w=$2
|
||||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file"
|
||||
exit 1
|
||||
}
|
||||
|
||||
video() {
|
||||
file=$1
|
||||
w=$2
|
||||
h=$3
|
||||
x=$4
|
||||
y=$5
|
||||
thumb="$(vidthumb "$file")"
|
||||
if [ "$thumb" != "" ]; then
|
||||
kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$thumb"
|
||||
exit 1
|
||||
fi
|
||||
mediainfo "$file"
|
||||
exit 1
|
||||
}
|
||||
|
||||
batorcat() {
|
||||
file="$1"
|
||||
shift
|
||||
if command -v bat > /dev/null 2>&1; then
|
||||
bat --color=always --style=plain --pager=never "$file" "$@"
|
||||
elif command -v batcat > /dev/null 2>&1; then
|
||||
batcat --color=always --style=plain --pager=never "$file" "$@"
|
||||
else
|
||||
cat "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
|
||||
|
||||
case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
|
||||
*.md) glow "$1" && exit 0 ;;
|
||||
*.xml|*.html) w3m -dump "$1" && exit 0 ;;
|
||||
*.[1-8]) man "$1" | col -b && exit 0 ;;
|
||||
*.o) nm "$1" && exit 0 ;;
|
||||
esac
|
||||
|
||||
case "$(file -bL --mime-type $1)" in
|
||||
application/gzip) tar tzf "$1" ;;
|
||||
application/x-bzip2) tar tjf "$1" ;;
|
||||
application/x-xz) xz --list "$1" ;;
|
||||
application/x-tar) tar tf "$1" ;;
|
||||
application/zip) unzip -l "$1" ;;
|
||||
application/java-archive) unzip -l "$1" ;;
|
||||
application/x-rar) unrar l "$1" ;;
|
||||
application/x-7z-compressed) 7z l "$1" ;;
|
||||
application/x-iso9660-image) iso-info --no-header -l "$1" ;;
|
||||
application/x-bittorrent) transmission-show "$1" ;;
|
||||
application/vnd.sun.xml.writer) odt2txt "$1" ;;
|
||||
application/msword) catdoc "$1" ;;
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document) docx2txt < "$1" ;;
|
||||
application/vnd.ms-excel) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
||||
application/epub+zip) [ ! -f "$CACHE" ] && epub-thumbnailer "$1" "$CACHE" 1024; image "$CACHE" "$2" "$3" "$4" "$5" ;;
|
||||
application/pgp-encrypted) gpg -d -- "$1" ;;
|
||||
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
||||
video/*) video "$1" "$2" "$3" "$4" "$5" ;;
|
||||
*opendocument*) odt2txt "$1" ;;
|
||||
text/*|*/xml|application/json) batorcat "$1" ;;
|
||||
*/pdf) [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"; image "${CACHE}.jpg" "$2" "$3" "$4" "$5" ;;
|
||||
*) mediainfo "$1" || exit 1 ;;
|
||||
esac
|
||||
exit 0
|
|
@ -0,0 +1,28 @@
|
|||
map Cch cd "/home/luca/.cache"
|
||||
map Ccf cd "/home/luca/.config"
|
||||
map Cdt cd "/home/luca/.local/share"
|
||||
map Crr cd "/home/luca/.local/src"
|
||||
map Csc cd "/home/luca/.local/bin"
|
||||
map Cmn cd "/mnt"
|
||||
map Cdl cd "/home/luca/Downloads"
|
||||
map Cdm cd "/home/luca/Documents"
|
||||
map Cms cd "/home/luca/Music"
|
||||
map Cpc cd "/home/luca/Pictures"
|
||||
map Cvd cd "/home/luca/Videos"
|
||||
map Cdot cd "/home/luca/.local/share/dotfiles"
|
||||
map Ebf $$EDITOR "/home/luca/.config/shell/bm-files"
|
||||
map Ebd $$EDITOR "/home/luca/.config/shell/bm-dirs"
|
||||
map Ecfx $$EDITOR "/home/luca/.config/x11/xresources"
|
||||
map Ecfb $$EDITOR "/home/luca/.local/src/dwmblocks/config.h"
|
||||
map Ecfv $$EDITOR "/home/luca/.config/nvim/init.vim"
|
||||
map Ecfz $$EDITOR "/.zshrc"
|
||||
map Ecfa $$EDITOR "/home/luca/.config/shell/aliasrc"
|
||||
map Ecfp $$EDITOR "/home/luca/.config/shell/profile"
|
||||
map Ecfm $$EDITOR "/home/luca/.config/mutt/muttrc"
|
||||
map Ecfn $$EDITOR "/home/luca/.config/newsboat/config"
|
||||
map Ecfu $$EDITOR "/home/luca/.config/newsboat/urls"
|
||||
map Ecfmb $$EDITOR "/home/luca/.config/ncmpcpp/bindings"
|
||||
map Ecfmc $$EDITOR "/home/luca/.config/ncmpcpp/config"
|
||||
map Ecfl $$EDITOR "/home/luca/.config/lf/lfrc"
|
||||
map EcfL $$EDITOR "/home/luca/.config/lf/scope"
|
||||
map EcfX $$EDITOR "/home/luca/.config/sxiv/exec/key-handler"
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Verbosity and settings that you pretty much just always are going to want.
|
||||
alias \
|
||||
cp="cp -iv" \
|
||||
mv="mv -iv" \
|
||||
rm="rm -vI" \
|
||||
mkd="mkdir -pv" \
|
||||
exa="exa -abghHliS" \
|
||||
duf="duf -all" \
|
||||
ls="ls -hN --color=auto --group-directories-first" \
|
||||
grep="grep --color=auto" \
|
||||
diff="diff --color=auto" \
|
||||
ccat="highlight --out-format=ansi" \
|
||||
ip="ip -color=auto"
|
||||
|
||||
# These common commands are just too long! Abbreviate them.
|
||||
alias \
|
||||
ka="killall" \
|
||||
e="$EDITOR" \
|
||||
au="apt uninstall" \
|
||||
ar="apt reinstall" \
|
||||
ai="apt install" \
|
||||
aur="apt autoremove" \
|
||||
|
||||
# Misc.
|
||||
alias \
|
||||
vim="nvim" \
|
|
@ -0,0 +1,19 @@
|
|||
$include /etc/inputrc
|
||||
set editing-mode vi
|
||||
$if mode=vi
|
||||
|
||||
set show-mode-in-prompt on
|
||||
set vi-ins-mode-string \1\e[6 q\2
|
||||
set vi-cmd-mode-string \1\e[2 q\2
|
||||
|
||||
set keymap vi-command
|
||||
# these are for vi-command mode
|
||||
Control-l: clear-screen
|
||||
Control-a: beginning-of-line
|
||||
|
||||
set keymap vi-insert
|
||||
# these are for vi-insert mode
|
||||
Control-l: clear-screen
|
||||
Control-a: beginning-of-line
|
||||
|
||||
$endif
|
|
@ -0,0 +1,209 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# profile file. Runs on login. Environmental variables are set here.
|
||||
|
||||
# Adds `~/.local/bin` to $PATH
|
||||
export PATH="$PATH:${$(find -L ~/.local/bin -type d -printf %p:)%%:}"
|
||||
|
||||
# Adds `~/.local/share/npm-global` to $PATH
|
||||
export PATH=~/.npm-global/bin:$PATH
|
||||
|
||||
# Default programs:
|
||||
export EDITOR="nvim"
|
||||
|
||||
# ~/ Clean-up:
|
||||
export XDG_CONFIG_HOME="$HOME/.config"
|
||||
export XDG_DATA_HOME="$HOME/.local/share"
|
||||
export XDG_CACHE_HOME="$HOME/.cache"
|
||||
export PYENVS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/pyenvs"
|
||||
export ZSH_COMPDUMP="${XDG_CACHE_HOME:~/.cache}/zcompdump"
|
||||
export LESSHISTFILE="-"
|
||||
export WGETRC="${XDG_CONFIG_HOME:-$HOME/.config}/wget/wgetrc"
|
||||
export INPUTRC="${XDG_CONFIG_HOME:-$HOME/.config}/shell/inputrc"
|
||||
export ZDOTDIR="${XDG_CONFIG_HOME:-$HOME/.config}/zsh"
|
||||
export GNUPGHOME="${XDG_CONFIG_HOME:-$HOME/.config}/gnupg"
|
||||
export PASSWORD_STORE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/password-store"
|
||||
export TMUX_TMPDIR="$XDG_RUNTIME_DIR"
|
||||
export CARGO_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/cargo"
|
||||
export GOPATH="${XDG_DATA_HOME:-$HOME/.local/share}/go"
|
||||
export HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/history"
|
||||
|
||||
# Other program settings:
|
||||
export FZF_DEFAULT_OPTS="--layout=reverse --height 40%"
|
||||
export LESS=-R
|
||||
export LESS_TERMCAP_mb="$(printf '%b' '[1;31m')"
|
||||
export LESS_TERMCAP_md="$(printf '%b' '[1;36m')"
|
||||
export LESS_TERMCAP_me="$(printf '%b' '[0m')"
|
||||
export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')"
|
||||
export LESS_TERMCAP_se="$(printf '%b' '[0m')"
|
||||
export LESS_TERMCAP_us="$(printf '%b' '[1;32m')"
|
||||
export LESS_TERMCAP_ue="$(printf '%b' '[0m')"
|
||||
export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null"
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
export PYENV_PROMPT=" %F{yellow\}%F{reset\} "
|
||||
|
||||
# This is the list for lf icons:
|
||||
export LF_ICONS="\
|
||||
tw=:\
|
||||
st=:\
|
||||
ow=:\
|
||||
dt=:\
|
||||
di=:\
|
||||
fi=:\
|
||||
ln=:\
|
||||
or=:\
|
||||
ex=:\
|
||||
*.c=:\
|
||||
*.cc=:\
|
||||
*.clj=:\
|
||||
*.coffee=:\
|
||||
*.cpp=:\
|
||||
*.css=:\
|
||||
*.d=:\
|
||||
*.dart=:\
|
||||
*.erl=:\
|
||||
*.exs=:\
|
||||
*.fs=:\
|
||||
*.go=:\
|
||||
*.h=:\
|
||||
*.hh=:\
|
||||
*.hpp=:\
|
||||
*.hs=:\
|
||||
*.html=:\
|
||||
*.java=:\
|
||||
*.jl=:\
|
||||
*.js=:\
|
||||
*.json=:\
|
||||
*.lua=:\
|
||||
*.md=:\
|
||||
*.php=:\
|
||||
*.pl=:\
|
||||
*.pro=:\
|
||||
*.py=:\
|
||||
*.rb=:\
|
||||
*.rs=:\
|
||||
*.scala=:\
|
||||
*.ts=:\
|
||||
*.vim=:\
|
||||
*.cmd=:\
|
||||
*.ps1=:\
|
||||
*.sh=:\
|
||||
*.bash=:\
|
||||
*.zsh=:\
|
||||
*.fish=:\
|
||||
*.tar=:\
|
||||
*.tgz=:\
|
||||
*.arc=:\
|
||||
*.arj=:\
|
||||
*.taz=:\
|
||||
*.lha=:\
|
||||
*.lz4=:\
|
||||
*.lzh=:\
|
||||
*.lzma=:\
|
||||
*.tlz=:\
|
||||
*.txz=:\
|
||||
*.tzo=:\
|
||||
*.t7z=:\
|
||||
*.zip=:\
|
||||
*.z=:\
|
||||
*.dz=:\
|
||||
*.gz=:\
|
||||
*.lrz=:\
|
||||
*.lz=:\
|
||||
*.lzo=:\
|
||||
*.xz=:\
|
||||
*.zst=:\
|
||||
*.tzst=:\
|
||||
*.bz2=:\
|
||||
*.bz=:\
|
||||
*.tbz=:\
|
||||
*.tbz2=:\
|
||||
*.tz=:\
|
||||
*.deb=:\
|
||||
*.rpm=:\
|
||||
*.jar=:\
|
||||
*.war=:\
|
||||
*.ear=:\
|
||||
*.sar=:\
|
||||
*.rar=:\
|
||||
*.alz=:\
|
||||
*.ace=:\
|
||||
*.zoo=:\
|
||||
*.cpio=:\
|
||||
*.7z=:\
|
||||
*.rz=:\
|
||||
*.cab=:\
|
||||
*.wim=:\
|
||||
*.swm=:\
|
||||
*.dwm=:\
|
||||
*.esd=:\
|
||||
*.jpg=:\
|
||||
*.jpeg=:\
|
||||
*.mjpg=:\
|
||||
*.mjpeg=:\
|
||||
*.gif=:\
|
||||
*.bmp=:\
|
||||
*.pbm=:\
|
||||
*.pgm=:\
|
||||
*.ppm=:\
|
||||
*.tga=:\
|
||||
*.xbm=:\
|
||||
*.xpm=:\
|
||||
*.tif=:\
|
||||
*.tiff=:\
|
||||
*.png=:\
|
||||
*.svg=:\
|
||||
*.svgz=:\
|
||||
*.mng=:\
|
||||
*.pcx=:\
|
||||
*.mov=:\
|
||||
*.mpg=:\
|
||||
*.mpeg=:\
|
||||
*.m2v=:\
|
||||
*.mkv=:\
|
||||
*.webm=:\
|
||||
*.ogm=:\
|
||||
*.mp4=:\
|
||||
*.m4v=:\
|
||||
*.mp4v=:\
|
||||
*.vob=:\
|
||||
*.qt=:\
|
||||
*.nuv=:\
|
||||
*.wmv=:\
|
||||
*.asf=:\
|
||||
*.rm=:\
|
||||
*.rmvb=:\
|
||||
*.flc=:\
|
||||
*.avi=:\
|
||||
*.fli=:\
|
||||
*.flv=:\
|
||||
*.gl=:\
|
||||
*.dl=:\
|
||||
*.xcf=:\
|
||||
*.xwd=:\
|
||||
*.yuv=:\
|
||||
*.cgm=:\
|
||||
*.emf=:\
|
||||
*.ogv=:\
|
||||
*.ogx=:\
|
||||
*.aac=:\
|
||||
*.au=:\
|
||||
*.flac=:\
|
||||
*.m4a=:\
|
||||
*.mid=:\
|
||||
*.midi=:\
|
||||
*.mka=:\
|
||||
*.mp3=:\
|
||||
*.mpc=:\
|
||||
*.ogg=:\
|
||||
*.ra=:\
|
||||
*.wav=:\
|
||||
*.oga=:\
|
||||
*.opus=:\
|
||||
*.spx=:\
|
||||
*.xspf=:\
|
||||
*.pdf=:\
|
||||
*.nix=:\
|
||||
"
|
||||
|
||||
[ ! -f ${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc ] && setsid shortcuts >/dev/null 2>&1
|
|
@ -0,0 +1,115 @@
|
|||
# Enable colors and change prompt:
|
||||
autoload -U colors && colors # Load colors
|
||||
PS1="%B%F{blue}%n%F{cyan}@%F{blue}%m %F{magenta}[%f%3~%F{magenta}] %(?.%F{green}.%F{red})»%f%b "
|
||||
RPS1="%(?..%F{red}%?)"
|
||||
stty stop undef # Disable ctrl-s to freeze terminal.
|
||||
setopt HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS HIST_VERIFY BANG_HIST interactive_comments autocd
|
||||
|
||||
# History in cache directory:
|
||||
HISTSIZE=10000000
|
||||
SAVEHIST=10000000
|
||||
|
||||
# Load aliases and shortcuts if existent.
|
||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc"
|
||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc"
|
||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc"
|
||||
|
||||
# Basic auto/tab complete:
|
||||
autoload -U compinit
|
||||
zstyle ':completion:*' menu select
|
||||
zmodload zsh/complist
|
||||
compinit
|
||||
_comp_options+=(globdots) # Include hidden files.
|
||||
|
||||
# vi mode
|
||||
autoload -Uz edit-command-line
|
||||
zle -N edit-command-line
|
||||
bindkey -M vicmd v edit-command-line
|
||||
bindkey -v
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
# Use vim keys in tab complete menu:
|
||||
bindkey -M menuselect 'h' vi-backward-char
|
||||
bindkey -M menuselect 'k' vi-up-line-or-history
|
||||
bindkey -M menuselect 'l' vi-forward-char
|
||||
bindkey -M menuselect 'j' vi-down-line-or-history
|
||||
|
||||
# Change cursor shape for different vi modes.
|
||||
function zle-keymap-select () {
|
||||
case $KEYMAP in
|
||||
vicmd) echo -ne '\e[1 q';; # block
|
||||
viins|main) echo -ne '\e[5 q';; # beam
|
||||
esac
|
||||
}
|
||||
zle -N zle-keymap-select
|
||||
zle-line-init() {
|
||||
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
|
||||
echo -ne "\e[5 q"
|
||||
}
|
||||
zle -N zle-line-init
|
||||
echo -ne '\e[5 q' # Use beam shape cursor on startup.
|
||||
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
|
||||
|
||||
# Use lf to switch directories and bind it to ctrl-o
|
||||
lfcd () {
|
||||
tmp="$(mktemp)"
|
||||
fid="$(mktemp)"
|
||||
lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@"
|
||||
id="$(cat "$fid")"
|
||||
archivemount_dir="/tmp/__lf_archivemount_$id"
|
||||
if [ -f "$archivemount_dir" ]; then
|
||||
cat "$archivemount_dir" | \
|
||||
while read -r line; do
|
||||
sudo umount "$line"
|
||||
rmdir "$line"
|
||||
done
|
||||
command rm -f "$archivemount_dir"
|
||||
fi
|
||||
if [ -f "$tmp" ]; then
|
||||
dir="$(cat "$tmp")"
|
||||
command rm -f "$tmp"
|
||||
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
|
||||
fi
|
||||
tput cuu1;tput el
|
||||
}
|
||||
|
||||
_lfcd () {
|
||||
BUFFER="lfcd"
|
||||
zle accept-line
|
||||
}
|
||||
zle -N _lfcd
|
||||
bindkey '^o' _lfcd
|
||||
|
||||
# bind lazygit to ctrl-g
|
||||
lg () {
|
||||
lazygit
|
||||
tput cuu1;tput el
|
||||
}
|
||||
|
||||
_lazygit () {
|
||||
BUFFER="lg"
|
||||
zle accept-line
|
||||
}
|
||||
|
||||
zle -N _lazygit
|
||||
bindkey '^g' _lazygit
|
||||
|
||||
# Edit line in vim with ctrl-e:
|
||||
autoload edit-command-line; zle -N edit-command-line
|
||||
bindkey '^e' edit-command-line
|
||||
|
||||
# other keybinds
|
||||
bindkey -v '^?' backward-delete-char
|
||||
bindkey '^[[P' delete-char
|
||||
bindkey "^[[H" beginning-of-line
|
||||
bindkey '^[[F' end-of-line
|
||||
bindkey '^[[1;5C' forward-word
|
||||
bindkey '^[[1;5D' backward-word
|
||||
|
||||
|
||||
|
||||
PLUGINS_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/zsh/plugins"
|
||||
[ -f "$PLUGINS_HOME/fzf/key-bindings.zsh" ] && source "$PLUGINS_HOME/fzf/key-bindings.zsh"
|
||||
[ -f "$PLUGINS_HOME/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" ] && source "$PLUGINS_HOME/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
|
||||
[ -f "$PLUGINS_HOME/autopyenv/autopyenv.plugin.zsh" ] && source "$PLUGINS_HOME/autopyenv/autopyenv.plugin.zsh"
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
PYENV_DIR="${PYENVS_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/virtualenv}"
|
||||
PS1_DEFAULT="$PS1"
|
||||
function chpwd_activate(){
|
||||
[[ "$(pwd)" == "/" ]] && return 0
|
||||
for pydir in $(ls $PYENV_DIR); do
|
||||
if [[ "$(pwd|sed -e s@/@_@g|cut -c2-)" =~ "^${pydir}$" ]] || [[ "r-$(pwd|sed -e s@/@_@g|cut -c2-)" =~ "^${pydir}(_.+)?$" ]]; then
|
||||
if [ "x$VIRTUAL_ENV" != "x$PYENV_DIR/$pydir" ]; then
|
||||
export PS1="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }$PS1"
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
source "$PYENV_DIR/$pydir/bin/activate"
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
fi
|
||||
return
|
||||
fi
|
||||
done
|
||||
if [ "x$VIRTUAL_ENV" != "x" ]; then
|
||||
export PS1="$PS1_DEFAULT"
|
||||
deactivate
|
||||
fi
|
||||
}
|
||||
|
||||
function venv(){
|
||||
[[ "$(pwd)" == "/" ]] && echo "Cannot create venv at root" && return 1
|
||||
[[ "$(pwd)" != "/" ]] && envdir=$(pwd|sed -e s@/@_@g|cut -c2-)
|
||||
[[ "$1" == "-r" ]] && envdir="r-$envdir" # create a venv that will be activated for all subdirectories as well
|
||||
if [ ! -e "$PYENV_DIR/${envdir}" ]; then
|
||||
echo "Creating python venv for ${envdir}.."
|
||||
mkdir "$PYENV_DIR" -p
|
||||
python3 -m venv "$PYENV_DIR/${envdir}"
|
||||
echo "Activating virtual env ${envdir}"
|
||||
[[ ! $PS1 =~ "^${PYENV_PROMPT:- %F{yellow\}%F{reset\} }" ]] && export PS1="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }$PS1"
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
source "$PYENV_DIR/${envdir}/bin/activate"
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
else
|
||||
echo "A venv for this path already exists"
|
||||
fi
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook chpwd chpwd_activate
|
Loading…
Reference in New Issue