aboutsummaryrefslogtreecommitdiffstats
path: root/nix-conf
diff options
context:
space:
mode:
authorDavid Morgan <djm_uk@protonmail.com>2025-04-24 08:49:28 +0100
committerDavid Morgan <djm_uk@protonmail.com>2025-04-24 08:49:28 +0100
commit57efa646a6c7aa2a73e0fcf2948effaee5b0e476 (patch)
tree6402e38e1e9673355436a84edb974669624010d4 /nix-conf
parent7bdd64cd139e34f6f402ca42e1a4056948de75c7 (diff)
downloaddotfiles-57efa646a6c7aa2a73e0fcf2948effaee5b0e476.tar.gz
programs.zsh.initExtra{,First} -> initContent
Diffstat (limited to 'nix-conf')
-rw-r--r--nix-conf/home/includes/zsh.nix322
1 files changed, 162 insertions, 160 deletions
diff --git a/nix-conf/home/includes/zsh.nix b/nix-conf/home/includes/zsh.nix
index 982675a..ffa2f0d 100644
--- a/nix-conf/home/includes/zsh.nix
+++ b/nix-conf/home/includes/zsh.nix
@@ -144,189 +144,191 @@ in
LESS = "-iRXF";
};
- initExtraFirst = ''
- [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return
- '';
- initExtra = ''
- # Based on prezto tmux plugin
- if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && (-z "$SSH_TTY" || -n "$TMUX_AUTO_ATTACH") ]]; then
- tmux start-server
+ initContent = lib.mkMerge [
+ (lib.mkBefore ''
+ [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return
+ '')
+ ''
+ # Based on prezto tmux plugin
+ if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && (-z "$SSH_TTY" || -n "$TMUX_AUTO_ATTACH") ]]; then
+ tmux start-server
+
+ if ! tmux has-session 2> /dev/null; then
+ tmux new-session -d -s "0" \; set-option -t "0" destroy-unattached off &> /dev/null
+ fi
- if ! tmux has-session 2> /dev/null; then
- tmux new-session -d -s "0" \; set-option -t "0" destroy-unattached off &> /dev/null
+ if [[ -n "$SSH_TTY" ]]; then
+ exec tmux -u attach-session
+ else
+ exec tmux -u attach-session -d
+ fi
fi
- if [[ -n "$SSH_TTY" ]]; then
- exec tmux -u attach-session
- else
- exec tmux -u attach-session -d
- fi
- fi
-
- autopair-init
- enable-fzf-tab
-
- # make home and end work
- [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
- [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
-
- # disable sort when completing `git checkout`
- zstyle ':completion:*:git-checkout:*' sort false
- # set descriptions format to enable group support
- zstyle ':completion:*:descriptions' format '[%d]'
- # Allow tab to expand aliases
- zstyle ':completion:*' completer _expand_alias _complete _ignored
- # set list-colors to enable filename colorizing
- #zstyle ':completion:*' list-colors ''${(s.:.)LS_COLORS}
- # preview directory's content with eza when completing cd
- zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
- # switch group using `,` and `.`
- zstyle ':fzf-tab:*' switch-group ',' '.'
-
- # functions modified from https://www.josean.com/posts/7-amazing-cli-tools
- _fzf_compgen_path() {
- fd --hidden --exclude .git --exclude node_modules . "$1"
- }
- _fzf_compgen_dir() {
- fd --type=d --hidden --exclude .git --exclude node_modules . "$1"
- }
- _fzf_comprun() {
- local command=$1
- shift
-
- case "$command" in
- cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
- export|unset) fzf --preview "eval 'echo $'{}" "$@" ;;
- ssh) fzf --preview 'dig {}' "$@" ;;
- *) fzf --preview "${show_file_or_dir_preview}" "$@" ;;
- esac
- }
+ autopair-init
+ enable-fzf-tab
+
+ # make home and end work
+ [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
+ [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
+
+ # disable sort when completing `git checkout`
+ zstyle ':completion:*:git-checkout:*' sort false
+ # set descriptions format to enable group support
+ zstyle ':completion:*:descriptions' format '[%d]'
+ # Allow tab to expand aliases
+ zstyle ':completion:*' completer _expand_alias _complete _ignored
+ # set list-colors to enable filename colorizing
+ #zstyle ':completion:*' list-colors ''${(s.:.)LS_COLORS}
+ # preview directory's content with eza when completing cd
+ zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
+ # switch group using `,` and `.`
+ zstyle ':fzf-tab:*' switch-group ',' '.'
+
+ # functions modified from https://www.josean.com/posts/7-amazing-cli-tools
+ _fzf_compgen_path() {
+ fd --hidden --exclude .git --exclude node_modules . "$1"
+ }
+ _fzf_compgen_dir() {
+ fd --type=d --hidden --exclude .git --exclude node_modules . "$1"
+ }
+ _fzf_comprun() {
+ local command=$1
+ shift
+
+ case "$command" in
+ cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
+ export|unset) fzf --preview "eval 'echo $'{}" "$@" ;;
+ ssh) fzf --preview 'dig {}' "$@" ;;
+ *) fzf --preview "${show_file_or_dir_preview}" "$@" ;;
+ esac
+ }
- set -o noclobber
-
- # disable flow control (so that fzf-git.sh's ^g^s can work)
- stty -ixon
-
- # These functions are called as follows, after using ea (using vip as an example):
- # vip # edits the first result from ea (roughly equivalent to vi `ea p 1`)
- # vip <n> # edits the nth result from ea (vi `ea p <n>`)
- # vip <n> foo # if the nth result from ea is a directory, edit foo in that directory (vi `ea p <n>`/foo)
- # Will add +<line-number>, where the line number is available
- function _vip () {
- local cmd=(''${=1}) # zsh only, not portable; something like CMD=($(echo $1)) is more portable but is ugly
- local idx=''${2:-1}
- local base_path=$(ea p $idx)
- local line=$(ea p $idx "{line}")
- local ea_format="'{path}'"
-
- if [ -z "$base_path" ]; then
- echo "No file path found for index $2"
- return 1
- fi
+ set -o noclobber
+
+ # disable flow control (so that fzf-git.sh's ^g^s can work)
+ stty -ixon
+
+ # These functions are called as follows, after using ea (using vip as an example):
+ # vip # edits the first result from ea (roughly equivalent to vi `ea p 1`)
+ # vip <n> # edits the nth result from ea (vi `ea p <n>`)
+ # vip <n> foo # if the nth result from ea is a directory, edit foo in that directory (vi `ea p <n>`/foo)
+ # Will add +<line-number>, where the line number is available
+ function _vip () {
+ local cmd=(''${=1}) # zsh only, not portable; something like CMD=($(echo $1)) is more portable but is ugly
+ local idx=''${2:-1}
+ local base_path=$(ea p $idx)
+ local line=$(ea p $idx "{line}")
+ local ea_format="'{path}'"
+
+ if [ -z "$base_path" ]; then
+ echo "No file path found for index $2"
+ return 1
+ fi
- if [ $# -gt 2 -a ! -d "$base_path" ]; then
- echo "$base_path is not a directory"
- return 2
- fi
+ if [ $# -gt 2 -a ! -d "$base_path" ]; then
+ echo "$base_path is not a directory"
+ return 2
+ fi
- if [ $# -lt 3 -a $line -ne 1 ]; then
- ea_format+=" +{line}"
- fi
+ if [ $# -lt 3 -a $line -ne 1 ]; then
+ ea_format+=" +{line}"
+ fi
- eval $(ea p $idx "$cmd ''${ea_format}$3")
- }
+ eval $(ea p $idx "$cmd ''${ea_format}$3")
+ }
- function vip () {
- _vip $EDITOR ''${@}
- }
- function bp () {
- _vip bat ''${@}
- }
- function bpp () {
- # this will be split into an array in _vip
- CMD="bat -p"
- _vip $CMD ''${@}
- }
+ function vip () {
+ _vip $EDITOR ''${@}
+ }
+ function bp () {
+ _vip bat ''${@}
+ }
+ function bpp () {
+ # this will be split into an array in _vip
+ CMD="bat -p"
+ _vip $CMD ''${@}
+ }
- function generate () { gopass generate -s -p $1 $((RANDOM % 14 + 45)) }
- function fcd { cd $(fd -L --max-depth=''${1:-4} --type=d 2>/dev/null | fzf-tmux) }
+ function generate () { gopass generate -s -p $1 $((RANDOM % 14 + 45)) }
+ function fcd { cd $(fd -L --max-depth=''${1:-4} --type=d 2>/dev/null | fzf-tmux) }
- fif() {
- if [ ! "$#" -gt 0 ]; then
- echo "usage: fif <SEARCH_TERM>"
- return 1;
- fi
- rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}"
- }
+ fif() {
+ if [ ! "$#" -gt 0 ]; then
+ echo "usage: fif <SEARCH_TERM>"
+ return 1;
+ fi
+ rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}"
+ }
- fe() {
- IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
- [[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}"
- }
+ fe() {
+ IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
+ [[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}"
+ }
- # TODO is there a way to do this in shellAliases
- alias ..="cd .."
- alias ...="cd ../.."
- alias -- -="cd -"
-
- .,() {
- local declare dirs=()
- get_parent_dirs() {
- if [[ -d "''${1}" ]]; then dirs+=("$1"); else return; fi
- if [[ "''${1}" == '/' ]]; then
- for _dir in "''${dirs[@]}"; do echo $_dir; done
- else
- get_parent_dirs $(dirname "$1")
- fi
+ # TODO is there a way to do this in shellAliases
+ alias ..="cd .."
+ alias ...="cd ../.."
+ alias -- -="cd -"
+
+ .,() {
+ local declare dirs=()
+ get_parent_dirs() {
+ if [[ -d "''${1}" ]]; then dirs+=("$1"); else return; fi
+ if [[ "''${1}" == '/' ]]; then
+ for _dir in "''${dirs[@]}"; do echo $_dir; done
+ else
+ get_parent_dirs $(dirname "$1")
+ fi
+ }
+ local DIR=$(get_parent_dirs $(realpath "$PWD/..") | fzf-tmux)
+ cd "$DIR"
}
- local DIR=$(get_parent_dirs $(realpath "$PWD/..") | fzf-tmux)
- cd "$DIR"
- }
- # From omz
- function mkcd () {
- mkdir -p $@ && cd ''${@:$#}
- }
+ # From omz
+ function mkcd () {
+ mkdir -p $@ && cd ''${@:$#}
+ }
- tre () { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
+ tre () { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
- function gcd () {
- if [ $# -eq 0 ] ; then
- echo "Number of days must be specified" >&2
- return 1
- fi
- if ! [[ $1 =~ '^[0-9]+$' ]] ; then
- echo "Number of days must be a number" >&2
- return 2
- fi
+ function gcd () {
+ if [ $# -eq 0 ] ; then
+ echo "Number of days must be specified" >&2
+ return 1
+ fi
+ if ! [[ $1 =~ '^[0-9]+$' ]] ; then
+ echo "Number of days must be a number" >&2
+ return 2
+ fi
- if [ $1 -eq 0 ] ; then
- GC_ARGS=(-d)
- else
- GC_ARGS=(--delete-older-than ''${1}d)
- fi
+ if [ $1 -eq 0 ] ; then
+ GC_ARGS=(-d)
+ else
+ GC_ARGS=(--delete-older-than ''${1}d)
+ fi
- DOAS=$(command -v doas)
+ DOAS=$(command -v doas)
- # Run as the current user (as well as root) to clean up hm generations
- nix-collect-garbage ''${GC_ARGS[@]}
- if [ -n $DOAS ] ; then
- $DOAS nix-collect-garbage ''${GC_ARGS[@]}
- fi
+ # Run as the current user (as well as root) to clean up hm generations
+ nix-collect-garbage ''${GC_ARGS[@]}
+ if [ -n $DOAS ] ; then
+ $DOAS nix-collect-garbage ''${GC_ARGS[@]}
+ fi
- df -h
- date
- }
+ df -h
+ date
+ }
- function checkout-pr () {
- git fetch ''${2:-upstream} pull/''${1}/head:pr-''${1}
- git switch pr-''${1}
- }
+ function checkout-pr () {
+ git fetch ''${2:-upstream} pull/''${1}/head:pr-''${1}
+ git switch pr-''${1}
+ }
- [[ ! -f ~/.zsh.local ]] || source ~/.zsh.local
+ [[ ! -f ~/.zsh.local ]] || source ~/.zsh.local
- [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
- '';
+ [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
+ ''
+ ];
plugins = with pkgs; [
{