2023-01-13 07:47:03 +00:00
|
|
|
{ config, pkgs, lib, isDarwin, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib) optionals;
|
|
|
|
in
|
2022-09-10 14:51:06 +00:00
|
|
|
{
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
zsh-completions
|
|
|
|
];
|
|
|
|
|
|
|
|
programs.fzf = {
|
|
|
|
enable = true;
|
|
|
|
enableZshIntegration = true;
|
|
|
|
};
|
|
|
|
programs.zoxide = {
|
|
|
|
enable = true;
|
|
|
|
enableZshIntegration = true;
|
|
|
|
};
|
|
|
|
programs.direnv = {
|
|
|
|
enable = true;
|
|
|
|
nix-direnv.enable = true;
|
|
|
|
};
|
|
|
|
programs.keychain = {
|
2022-09-16 05:50:50 +00:00
|
|
|
enable = lib.mkIf pkgs.stdenv.isLinux true;
|
2022-09-10 14:51:06 +00:00
|
|
|
agents = [ "ssh" "gpg"];
|
|
|
|
keys = [ "id_rsa" "id_ed25519" "C171251002C200F2" ];
|
|
|
|
# extraFlags = [ "--quiet" "--ignore-missing" ];
|
|
|
|
};
|
2022-11-05 16:17:36 +00:00
|
|
|
programs.command-not-found.enable = true;
|
2022-09-10 14:51:06 +00:00
|
|
|
programs.zsh = {
|
|
|
|
enable = true;
|
|
|
|
enableCompletion = true;
|
|
|
|
enableAutosuggestions = true;
|
|
|
|
defaultKeymap = "emacs";
|
|
|
|
history = {
|
|
|
|
size = 100000;
|
|
|
|
save = 100000;
|
2022-11-07 20:43:12 +00:00
|
|
|
expireDuplicatesFirst = true;
|
2022-09-10 14:51:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
profileExtra = ''
|
|
|
|
[[ -f ~/.nix-profile/etc/profile.d/nix.sh ]] && . ~/.nix-profile/etc/profile.d/nix.sh
|
|
|
|
path=(~/bin
|
|
|
|
~/.local/bin
|
|
|
|
~/go/bin/
|
|
|
|
$path)
|
|
|
|
'';
|
|
|
|
shellAliases = {
|
|
|
|
cp = "cp -iv";
|
|
|
|
mv = "mv -iv";
|
|
|
|
mkdir = "mkdir -v";
|
2022-12-02 12:21:36 +00:00
|
|
|
tree = "exa --tree";
|
2022-11-14 08:10:30 +00:00
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
pp = "pushbullet push \"Pixel\" link \"\${1}\" \"\${1}\"";
|
2022-11-14 08:10:30 +00:00
|
|
|
|
2022-11-12 16:31:11 +00:00
|
|
|
upgrade_emacs = "cp ~/.emacs.d/straight/versions/default.el ~/straight-versions-default-`date \"+%Y-%m-%d-%H%M%S\"`.el && emacs --batch -l \"~/.emacs.d/init.el\" -f \"my/upgrade-packages\"";
|
2022-11-07 20:41:11 +00:00
|
|
|
diff_emacs = "difft --color always --context 0 $(ls -d1v ~/straight-versions-default-*.el | tail -1) ~/.emacs.d/straight/versions/default.el | grep '\\[9[12]' | egrep -v '(gnu-elpa-mirror|nongnu-elpa|melpa|emacsmirror-mirror)'";
|
2022-11-14 08:10:30 +00:00
|
|
|
|
2022-11-12 20:42:48 +00:00
|
|
|
nix-up = "git -C ~/dotfiles pull && doas nix-channel --update && doas nixos-rebuild switch && nix-channel --update && home-manager switch && system-changes-report && hm-changes-report && df -h && date";
|
2022-11-23 16:45:51 +00:00
|
|
|
_nix-up = "doas nix-channel --update && doas nixos-rebuild switch && nix-channel --update && home-manager switch && system-changes-report && hm-changes-report && df -h && date";
|
2022-11-12 16:26:49 +00:00
|
|
|
home-up = "git -C ~/dotfiles pull && nix-channel --update && home-manager switch && hm-changes-report";
|
2022-11-23 16:45:51 +00:00
|
|
|
_home-up = "nix-channel --update && home-manager switch && hm-changes-report";
|
2023-01-20 12:07:29 +00:00
|
|
|
nix-hammer = "nix shell -f https://github.com/jtojnar/nixpkgs-hammering/archive/master.tar.gz -c nixpkgs-hammer";
|
2022-09-10 14:51:06 +00:00
|
|
|
|
2022-11-14 08:10:30 +00:00
|
|
|
fb = "fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}'";
|
|
|
|
|
2022-12-02 06:12:22 +00:00
|
|
|
zz = "z $PWD";
|
|
|
|
|
2023-01-12 12:11:38 +00:00
|
|
|
els = "ea run linear ls -- -1";
|
|
|
|
erg = "ea run grouped rg --";
|
|
|
|
fd = "ea run linear fd --";
|
|
|
|
|
2023-01-20 12:07:29 +00:00
|
|
|
git-reset-branch = "git fetch && git reset --hard origin/\$(git branch --show-current)";
|
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
# Git log aliases from the omz git plugin
|
|
|
|
gl = "git pull";
|
|
|
|
glg = "git log --stat";
|
|
|
|
glgp = "git log --stat -p";
|
|
|
|
glgg = "git log --graph";
|
|
|
|
glgga = "git log --graph --decorate --all";
|
|
|
|
glgm = "git log --graph --max-count=10";
|
2022-11-16 20:28:53 +00:00
|
|
|
glo_ = "git log --oneline --decorate";
|
2022-09-10 14:51:06 +00:00
|
|
|
glol = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\"";
|
|
|
|
glols = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\" --stat";
|
|
|
|
glod = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset\"";
|
|
|
|
glods = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset\" --date=short";
|
|
|
|
glola = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\" --all";
|
|
|
|
glog = "git log --oneline --decorate --graph";
|
|
|
|
gloga = "git log --oneline --decorate --graph --all";
|
|
|
|
};
|
2022-10-11 17:28:03 +00:00
|
|
|
|
2023-01-12 16:11:22 +00:00
|
|
|
localVariables = {
|
|
|
|
PER_DIRECTORY_HISTORY_TOGGLE = "^\\\\"; # ^\\ is ^#
|
2023-01-17 13:19:44 +00:00
|
|
|
HISTORY_START_WITH_GLOBAL = true;
|
|
|
|
|
|
|
|
ZSH_AUTOSUGGEST_STRATEGY = ["history" "completion"];
|
2023-01-12 16:25:52 +00:00
|
|
|
|
2023-01-12 16:11:22 +00:00
|
|
|
NVM_AUTO_USE = true;
|
|
|
|
NVM_LAZY_LOAD = true;
|
2023-01-12 16:25:52 +00:00
|
|
|
|
|
|
|
LSP_USE_PLISTS = true;
|
|
|
|
LESS = "-iRXF";
|
2023-01-12 16:11:22 +00:00
|
|
|
};
|
2022-12-02 06:55:24 +00:00
|
|
|
initExtraFirst = ''
|
|
|
|
[[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return
|
|
|
|
'';
|
2022-09-10 14:51:06 +00:00
|
|
|
initExtra = ''
|
2022-11-30 16:12:56 +00:00
|
|
|
# Based on prezto tmux plugin
|
2022-11-12 20:31:46 +00:00
|
|
|
if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && (-z "$SSH_TTY" || -n "$TMUX_AUTO_ATTACH") ]]; then
|
2022-09-10 14:51:06 +00:00
|
|
|
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
|
|
|
|
|
2022-11-30 16:12:56 +00:00
|
|
|
if [[ -n "$SSH_TTY" ]]; then
|
|
|
|
exec tmux -u attach-session
|
|
|
|
else
|
|
|
|
exec tmux -u attach-session -d
|
|
|
|
fi
|
2022-09-10 14:51:06 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-12 16:25:52 +00:00
|
|
|
# Keep these in initExtra, rather than localVariables, because the order matters
|
2022-09-10 14:51:06 +00:00
|
|
|
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null'
|
|
|
|
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
|
2023-01-12 16:25:52 +00:00
|
|
|
export FZF_ALT_C_COMMAND='rg --hidden --files --sort-files --null -g "!{.git,node_modules}/*" | xargs -0 dirname | sort -u'
|
2022-12-02 12:23:06 +00:00
|
|
|
export FZF_ALT_C_OPTS="--preview 'exa --tree {} | head -200'"
|
|
|
|
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind 'ctrl-t:toggle-preview'"
|
2022-12-03 16:28:17 +00:00
|
|
|
export FZF_DEFAULT_OPTS="--bind=ctrl-t:toggle-all --bind=ctrl-j:jump"
|
2022-10-11 17:28:03 +00:00
|
|
|
|
2022-12-03 16:29:07 +00:00
|
|
|
eval "$(batpipe)"
|
2022-09-10 14:51:06 +00:00
|
|
|
autopair-init
|
|
|
|
enable-fzf-tab
|
|
|
|
bindkey '^[[A' history-substring-search-up
|
|
|
|
bindkey '^[[B' history-substring-search-down
|
|
|
|
|
2022-11-07 13:08:56 +00:00
|
|
|
# make home and end work
|
|
|
|
[[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
|
2022-11-07 13:13:27 +00:00
|
|
|
[[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
|
2022-11-07 13:08:56 +00:00
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
# 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 exa when completing cd
|
|
|
|
zstyle ''\':fzf-tab:complete:cd:*''\' fzf-preview ''\'exa -1 --color=always ''$realpath''\'
|
|
|
|
# switch group using `,` and `.`
|
|
|
|
zstyle ''\':fzf-tab:*''\' switch-group ''\',''\' ''\'.''\'
|
2022-10-11 17:28:03 +00:00
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
set -o noclobber append_history share_history
|
|
|
|
|
2022-11-30 16:13:34 +00:00
|
|
|
# disable flow control (so that fzf-git.sh's ^g^s can work)
|
|
|
|
stty -ixon
|
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
function generate () { gopass generate -s -p $1 $((RANDOM % 14 + 45)) }
|
2022-12-15 16:24:17 +00:00
|
|
|
function fcd { cd $(fd -L --max-depth=''${1:-4} --type=d 2>/dev/null | fzf-tmux) }
|
2022-12-02 12:23:32 +00:00
|
|
|
|
|
|
|
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' {}"
|
|
|
|
}
|
2022-09-10 14:51:06 +00:00
|
|
|
|
2022-12-15 16:24:17 +00:00
|
|
|
fe() {
|
|
|
|
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
|
|
|
|
[[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
..() {
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2022-12-02 12:21:36 +00:00
|
|
|
tre () { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
|
|
|
|
|
2022-11-12 16:26:49 +00:00
|
|
|
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
|
|
|
|
|
2022-12-02 05:47:55 +00:00
|
|
|
DOAS=$(command -v doas)
|
2022-11-12 16:26:49 +00:00
|
|
|
if [ $1 -eq 0 ] ; then
|
2022-12-02 05:47:55 +00:00
|
|
|
$DOAS nix-collect-garbage -d
|
2022-11-12 16:26:49 +00:00
|
|
|
else
|
2022-12-02 05:47:55 +00:00
|
|
|
$DOAS nix-collect-garbage --delete-older-than ''${1}d
|
2022-11-12 16:26:49 +00:00
|
|
|
fi
|
2022-12-02 05:33:55 +00:00
|
|
|
df -h
|
2022-11-12 16:26:49 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 12:12:53 +00:00
|
|
|
function checkout-pr () {
|
|
|
|
git fetch ''${2:-upstream} pull/''${1}/head:pr-''${1}
|
|
|
|
git switch pr-''${1}
|
|
|
|
}
|
|
|
|
|
2022-09-29 12:09:00 +00:00
|
|
|
[[ ! -f ~/.zsh.local ]] || source ~/.zsh.local
|
|
|
|
|
2022-09-10 14:51:06 +00:00
|
|
|
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
|
|
|
|
'';
|
|
|
|
|
|
|
|
plugins = with pkgs; [
|
|
|
|
{
|
|
|
|
name = "zsh-autopair";
|
|
|
|
src = zsh-autopair;
|
|
|
|
file = "share/zsh/zsh-autopair/autopair.zsh";
|
|
|
|
}
|
2022-12-02 05:48:16 +00:00
|
|
|
{
|
|
|
|
name = "zsh-bd";
|
|
|
|
src = zsh-bd;
|
|
|
|
file = "share/zsh-bd/bd.zsh";
|
|
|
|
}
|
2022-09-10 14:51:06 +00:00
|
|
|
{
|
|
|
|
name = "zsh-fzf-tab";
|
|
|
|
src = zsh-fzf-tab;
|
|
|
|
file = "share/fzf-tab/fzf-tab.zsh";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "zsh-fast-syntax-highlighting";
|
2022-10-11 17:28:03 +00:00
|
|
|
src = zsh-fast-syntax-highlighting;
|
|
|
|
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
|
2022-09-10 14:51:06 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "zsh-powerlevel10k";
|
|
|
|
src = zsh-powerlevel10k;
|
2022-10-11 17:28:03 +00:00
|
|
|
file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
|
2022-09-10 14:51:06 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "zsh-history-substring-search";
|
2022-10-11 17:28:03 +00:00
|
|
|
src = zsh-history-substring-search;
|
|
|
|
file = "share/zsh-history-substring-search/zsh-history-substring-search.zsh";
|
2022-09-10 14:51:06 +00:00
|
|
|
}
|
|
|
|
{
|
2022-12-05 07:56:27 +00:00
|
|
|
name = "zsh-forgit";
|
|
|
|
src = zsh-forgit;
|
|
|
|
file = "share/zsh/zsh-forgit/forgit.plugin.zsh";
|
2022-09-10 14:51:06 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "zsh-edit";
|
2022-12-05 07:56:27 +00:00
|
|
|
src = zsh-edit;
|
|
|
|
file = "share/zsh/zsh-edit/zsh-edit.plugin.zsh";
|
2022-09-10 14:51:06 +00:00
|
|
|
}
|
2022-11-22 12:17:26 +00:00
|
|
|
{
|
|
|
|
name = "fzf-git.sh";
|
2023-02-02 16:05:26 +00:00
|
|
|
src = fzf-git-sh;
|
|
|
|
file = "share/zsh/fzf-git-sh/fzf-git.sh";
|
2022-11-22 12:17:26 +00:00
|
|
|
}
|
2023-01-12 16:11:22 +00:00
|
|
|
{
|
|
|
|
name = "per-directory-history";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "jimhester";
|
|
|
|
repo = "per-directory-history";
|
|
|
|
rev = "0687bbfd736da566472a6d67c2b45c501b73d405";
|
|
|
|
sha256 = "7Z0qaDhgopKt9BDKSqdziw9jsVgiLLafs30wPPbz+oo=";
|
|
|
|
};
|
|
|
|
file = "per-directory-history.zsh";
|
|
|
|
}
|
2023-01-13 07:47:03 +00:00
|
|
|
]
|
|
|
|
++ optionals stdenv.isDarwin [
|
2023-01-12 16:11:22 +00:00
|
|
|
{
|
|
|
|
name = "zsh-nvm";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "lukechilds";
|
|
|
|
repo = "zsh-nvm";
|
|
|
|
rev = "23067bd9bb6eb6f4737a3ea90cb0cb5e85f61ba2";
|
|
|
|
sha256 = "Zwdi7bezMFKaIKYwsSftu3mJSFvadEWmY2hYnU1Kpu4=";
|
|
|
|
};
|
|
|
|
file = "zsh-nvm.plugin.zsh";
|
|
|
|
}
|
2022-09-10 14:51:06 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|