1
0
Fork 0
nixos-config/home-manager/roles/zsh/zshrc
2023-01-29 12:33:27 +01:00

99 lines
2.9 KiB
Bash

if [[ -n "$SSH_CONNECTION" && -z "$TMUX" ]] {
exec mytmux
}
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
exec sway
fi
mkdir -p /var/run/user/$UID/tmp/downloads
function title {
emulate -L zsh
setopt prompt_subst
[[ "$INSIDE_EMACS" == *term* ]] && return
# if $2 is unset use $1 as default
# if it is set and empty, leave it as is
: ${2=$1}
case "$TERM" in
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|screen*|tmux*)
print -Pn "\e]2;${2:q}\a" # set window name
print -Pn "\e]1;${1:q}\a" # set tab name
;;
*)
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;${2:q}\a" # set window name
print -Pn "\e]1;${1:q}\a" # set tab name
else
# Try to use terminfo to set the title
# If the feature is available set title
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
echoti tsl
print -Pn "$1"
echoti fsl
fi
fi
;;
esac
}
setopt prompt_subst
autoload -U colors && colors # Enable colors in prompt
alias nom-build-remote="nom build --builders '@/etc/nix/machines'"
alias nix-build-remote="nix build --builders '@/etc/nix/machines'"
alias nixpkgs-review-pr-remote='nixpkgs-review pr --build-args "--builders @/etc/nix/machines"'
alias nixpkgs-review-rev-remote='nixpkgs-review rev --build-args "--builders @/etc/nix/machines"'
alias accounting='f() { if [[ "$1" == "" ]]; then year="buchhaltung" else year="$1" fi; hledger -f ~/git/buchhaltung/$year.journal ui -- --watch --theme=terminal -X€ -t -E}; f'
alias o=xdg-open
alias sudo='sudo -A'
alias s='sudo -A systemctl'
alias g='lazygit'
alias u='systemctl --user'
alias m=man
alias h='f() { if [[ "$1" == "" ]]; then hx .; else hx "$@"; fi}; f'
alias vim="echo use h"
alias r="NIX_AUTO_RUN=1"
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':chpwd:*' recent-dirs-max 100
if [[ $PWD == "$HOME" ]] {
cd "$(head -n1 ~/.chpwd-recent-dirs | sed s/\\$// | sed s/\'//g)"
}
fzf-history-search() {
LBUFFER=$( history | sed -E 's/ *[0-9]*\*? *//' | fzf +s --tac | sed -E 's/\\/\\\\/g')
zle redisplay
}
zle -N fzf-history-search
bindkey '^R' fzf-history-search
fzf-directory-history-search() {
LBUFFER=$( sed "s/\\$//;s/'//g" ~/.chpwd-recent-dirs | fzf +s | sed -E 's/\\/\\\\/g;s/^/cd /')
zle redisplay
}
zle -N fzf-directory-history-search
bindkey '^T' fzf-directory-history-search
fzf-directory-search() {
LBUFFER=$( fd -t d | fzf | sed -E 's/\\/\\\\/g;s/^/cd /')
zle redisplay
}
zle -N fzf-directory-search
bindkey '^S' fzf-directory-search
fzf-vim-search() {
LBUFFER=$( fd -t f | fzf | sed -E 's/\\/\\\\/g;s/^/hx /')
zle redisplay
}
zle -N fzf-vim-search
bindkey '^V' fzf-vim-search
fzf-git-checkout() {
LBUFFER=$( git branch --list | fzf | sed -E 's/ \* //;s/^/git checkout /')
zle redisplay
}
zle -N fzf-git-checkout
bindkey '^G' fzf-git-checkout