feat(zsh): switched back to zsh and histdb
This commit is contained in:
parent
57ed20dcd6
commit
054407efb4
|
@ -103,8 +103,8 @@ in {
|
||||||
"${modifier}+f" = "floating toggle";
|
"${modifier}+f" = "floating toggle";
|
||||||
"${modifier}+space" = "focus mode_toggle";
|
"${modifier}+space" = "focus mode_toggle";
|
||||||
|
|
||||||
"${modifier}+Comma" = "workspace prev";
|
"${modifier}+comma" = "workspace prev_on_output";
|
||||||
"${modifier}+Period" = "workspace next";
|
"${modifier}+period" = "workspace next_on_output";
|
||||||
|
|
||||||
"${modifier}+1" = "workspace number 1";
|
"${modifier}+1" = "workspace number 1";
|
||||||
"${modifier}+2" = "workspace number 2";
|
"${modifier}+2" = "workspace number 2";
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
optionals config.programs.firefox.enable [
|
optionals config.programs.firefox.enable [
|
||||||
".mozilla"
|
".mozilla"
|
||||||
]
|
]
|
||||||
++ optionals config.programs.atuin.enable [
|
|
||||||
".local/share/atuin"
|
|
||||||
]
|
|
||||||
++ optionals config.programs.direnv.enable [
|
++ optionals config.programs.direnv.enable [
|
||||||
".local/share/direnv"
|
".local/share/direnv"
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
init.defaultBranch = "main";
|
init.defaultBranch = "main";
|
||||||
pull.ff = "only";
|
pull.ff = "only";
|
||||||
pull.rebase = true;
|
pull.rebase = true;
|
||||||
|
push.autoSetupRemote = true;
|
||||||
};
|
};
|
||||||
signing = {
|
signing = {
|
||||||
key = null;
|
key = null;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
{
|
{
|
||||||
|
# nu does not allow language access to completions
|
||||||
|
# which makes it impossible to use custom completion menus
|
||||||
|
# ZSH is still unbeatable with their completions
|
||||||
programs.atuin.enableNushellIntegration = false;
|
programs.atuin.enableNushellIntegration = false;
|
||||||
programs.nushell = {
|
programs.nushell = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
@ -1,55 +1,83 @@
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
config,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
imports = [
|
imports = [
|
||||||
../starfish.nix
|
../starfish.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# for zsh-histdb
|
||||||
|
# TODO replace sqlite inplace with nix path
|
||||||
|
home.packages = [pkgs.sqlite];
|
||||||
|
|
||||||
|
# save history in xdg data home
|
||||||
|
home.sessionVariables.HISTDB_FILE = "${config.xdg.dataHome}/zsh/history.db";
|
||||||
|
|
||||||
# has to be enabled to support zsh reverse search
|
# has to be enabled to support zsh reverse search
|
||||||
programs.fzf.enable = true;
|
programs.fzf.enable = true;
|
||||||
|
|
||||||
programs.atuin = {
|
programs.carapace.enable = true;
|
||||||
enable = true;
|
|
||||||
settings.auto_sync = false;
|
programs.command-not-found.enable = true;
|
||||||
};
|
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
dotDir = ".config/zsh";
|
dotDir = ".config/zsh";
|
||||||
# Atuin makes completion and this really _really_ slows zsh startup time down
|
history = {
|
||||||
enableCompletion = false;
|
extended = true;
|
||||||
initExtra = lib.mkAfter (''
|
path = "${config.xdg.dataHome}/zsh/zsh_history";
|
||||||
function atuin-prefix-search() {
|
save = 1000000;
|
||||||
if out=$(${pkgs.sqlite}/bin/sqlite3 -readonly ~/.local/share/atuin/history.db \
|
share = false;
|
||||||
'SELECT command FROM history WHERE command LIKE cast('"x'$(str_to_hex "$_atuin_search_prefix")'"' as text) ||
|
};
|
||||||
"%" ORDER BY timestamp DESC LIMIT 1 OFFSET '"$_atuin_search_offset"); then
|
initExtra = builtins.readFile ./zshrc;
|
||||||
[[ -z "$out" ]] && return 1
|
|
||||||
BUFFER=$out
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
}; zle -N atuin-prefix-search
|
|
||||||
''
|
|
||||||
+ (builtins.readFile ./zshrc));
|
|
||||||
plugins = [
|
plugins = [
|
||||||
{
|
{
|
||||||
name = "fzf-tab";
|
name = "fzf-tab";
|
||||||
src = pkgs.fetchFromGitHub {
|
src = "${pkgs.zsh-fzf-tab}/share/fzf-tab";
|
||||||
owner = "aloxaf";
|
|
||||||
repo = "fzf-tab";
|
|
||||||
rev = "5a81e13792a1eed4a03d2083771ee6e5b616b9ab";
|
|
||||||
sha256 = "0lfl4r44ci0wflfzlzzxncrb3frnwzghll8p365ypfl0n04bkxvl";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "fast-syntax-highlighting";
|
name = "fast-syntax-highlighting";
|
||||||
src = pkgs.fetchFromGitHub {
|
src = "${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions";
|
||||||
owner = "zdharma-continuum";
|
}
|
||||||
repo = "fast-syntax-highlighting";
|
{
|
||||||
rev = "13d7b4e63468307b6dcb2dadf6150818f242cbff";
|
# TODO change to separate packages
|
||||||
sha256 = "0ghzqg1xfvqh9z23aga7aafrpxbp9bpy1r8vk4avi6b80p3iwsq2";
|
name = "zsh-histdb";
|
||||||
|
src = pkgs.stdenv.mkDerivation {
|
||||||
|
name = "zsh-histdb";
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "larkery";
|
||||||
|
repo = "zsh-histdb";
|
||||||
|
rev = "30797f0c50c31c8d8de32386970c5d480e5ab35d";
|
||||||
|
hash = "sha256-PQIFF8kz+baqmZWiSr+wc4EleZ/KD8Y+lxW2NT35/bg=";
|
||||||
|
};
|
||||||
|
patchPhase = ''
|
||||||
|
substituteInPlace "sqlite-history.zsh" "histdb-migrate" "histdb-merge" \
|
||||||
|
--replace "sqlite3" "${pkgs.sqlite}/bin/sqlite3"
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp -r * $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "zsh-histdb-skim";
|
||||||
|
src = pkgs.rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "zsh-histd-skim";
|
||||||
|
version = "0.8.6";
|
||||||
|
buildInputs = [pkgs.sqlite];
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "m42e";
|
||||||
|
repo = "zsh-histdb-skim";
|
||||||
|
rev = "v${version}";
|
||||||
|
hash = "sha256-lJ2kpIXPHE8qP0EBnLuyvatWMtepBobNAC09e7itGas=";
|
||||||
|
};
|
||||||
|
cargoHash = "sha256-BMy9Shy9KAx5+VbvH2WaA0wMFUNM5dqU/dssUNE1NWY=";
|
||||||
|
postInstall = ''
|
||||||
|
substituteInPlace zsh-histdb-skim-vendored.zsh \
|
||||||
|
--replace "zsh-histdb-skim" "$out/bin/zsh-histdb-skim"
|
||||||
|
cp zsh-histdb-skim-vendored.zsh $out/zsh-histdb-skim.plugin.zsh
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,54 +1,3 @@
|
||||||
function str_to_hex() {
|
|
||||||
local str="$1"
|
|
||||||
for (( i=0; i<${#str}; i++ )); do
|
|
||||||
printf "%02x" "'${str:$i:1}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function atuin-prefix-search-any-end() {
|
|
||||||
|
|
||||||
if [[ -v _atuin_search_prev_buffer ]] && [[ $_atuin_search_prev_buffer == $BUFFER ]]; then
|
|
||||||
_atuin_search_offset=$((_atuin_search_offset + $direction))
|
|
||||||
else
|
|
||||||
[[ "$direction" == -1 ]] && return 1
|
|
||||||
_atuin_search_offset=0
|
|
||||||
_atuin_search_prefix=$LBUFFER
|
|
||||||
_atuin_search_orig_buffer=$BUFFER
|
|
||||||
_atuin_search_orig_cursor=$CURSOR
|
|
||||||
fi
|
|
||||||
if [[ "$_atuin_search_offset" -ge 0 ]] && zle atuin-prefix-search; then
|
|
||||||
zle .end-of-line
|
|
||||||
_atuin_search_prev_buffer=$BUFFER
|
|
||||||
else
|
|
||||||
if [[ $_atuin_search_offset -lt 0 ]];then
|
|
||||||
_atuin_search_offset=0
|
|
||||||
BUFFER=$_atuin_search_orig_buffer
|
|
||||||
CURSOR=$_atuin_search_orig_cursor
|
|
||||||
else
|
|
||||||
_atuin_search_offset=$((_atuin_search_offset - 1))
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
zle reset-prompt
|
|
||||||
|
|
||||||
}; zle -N atuin-prefix-search-any-end
|
|
||||||
|
|
||||||
function atuin-reset-search() {
|
|
||||||
unset _atuin_search_prev_buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
autoload -U add-zle-hook-widget
|
|
||||||
add-zle-hook-widget line-init atuin-reset-search
|
|
||||||
|
|
||||||
function atuin-prefix-search-backward-end() {
|
|
||||||
direction=1 atuin-prefix-search-any-end
|
|
||||||
}; zle -N atuin-prefix-search-backward-end
|
|
||||||
|
|
||||||
function atuin-prefix-search-forward-end() {
|
|
||||||
direction=-1 atuin-prefix-search-any-end
|
|
||||||
}; zle -N atuin-prefix-search-forward-end
|
|
||||||
|
|
||||||
# Don't insert tabs when there is no completion (e.g. beginning of line)
|
# Don't insert tabs when there is no completion (e.g. beginning of line)
|
||||||
zstyle ':completion:*' insert-tab false
|
zstyle ':completion:*' insert-tab false
|
||||||
|
|
||||||
|
@ -102,9 +51,6 @@ zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls -lhF --group-directories-first -
|
||||||
# preview windown min size
|
# preview windown min size
|
||||||
zstyle ':fzf-tab:complete:cd:*' popup_pad 20 0
|
zstyle ':fzf-tab:complete:cd:*' popup_pad 20 0
|
||||||
|
|
||||||
# History settings
|
|
||||||
unset HISTFILE
|
|
||||||
|
|
||||||
# Emit an error when a glob has no match
|
# Emit an error when a glob has no match
|
||||||
setopt nomatch
|
setopt nomatch
|
||||||
# DisAllow extended globbing
|
# DisAllow extended globbing
|
||||||
|
@ -152,6 +98,11 @@ function zshaddhistory() {
|
||||||
[[ ! $1 =~ "$HISTORY_IGNORE_REGEX" ]]
|
[[ ! $1 =~ "$HISTORY_IGNORE_REGEX" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if autoload history-search-end; then
|
||||||
|
zle -N history-beginning-search-backward-end history-search-end
|
||||||
|
zle -N history-beginning-search-forward-end history-search-end
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete all keybinds and use emacs-like key bindings by default:
|
# Delete all keybinds and use emacs-like key bindings by default:
|
||||||
bindkey -d
|
bindkey -d
|
||||||
bindkey -e
|
bindkey -e
|
||||||
|
@ -210,6 +161,8 @@ function setup_keybinds() {
|
||||||
local keys_PageDown=( "${terminfo[knp]}" )
|
local keys_PageDown=( "${terminfo[knp]}" )
|
||||||
local keys_ShiftPageDown=( "${terminfo[kNXT]}" )
|
local keys_ShiftPageDown=( "${terminfo[kNXT]}" )
|
||||||
|
|
||||||
|
local keys_CtrlR=( "^R" )
|
||||||
|
|
||||||
bindkeys keys_Home beginning-of-line
|
bindkeys keys_Home beginning-of-line
|
||||||
bindkeys keys_End end-of-line
|
bindkeys keys_End end-of-line
|
||||||
bindkeys keys_Insert nop
|
bindkeys keys_Insert nop
|
||||||
|
@ -225,12 +178,12 @@ function setup_keybinds() {
|
||||||
bindkeys keys_CtrlDelete kill-line
|
bindkeys keys_CtrlDelete kill-line
|
||||||
bindkeys keys_AltDelete delete-word
|
bindkeys keys_AltDelete delete-word
|
||||||
|
|
||||||
bindkeys keys_Up atuin-prefix-search-backward-end
|
bindkeys keys_Up history-beginning-search-backward-end
|
||||||
bindkeys keys_ShiftUp up-line
|
bindkeys keys_ShiftUp up-line
|
||||||
bindkeys keys_CtrlUp nop
|
bindkeys keys_CtrlUp nop
|
||||||
bindkeys keys_AltUp nop
|
bindkeys keys_AltUp nop
|
||||||
|
|
||||||
bindkeys keys_Down atuin-prefix-search-forward-end
|
bindkeys keys_Down history-beginning-search-forward-end
|
||||||
bindkeys keys_ShiftDown down-line
|
bindkeys keys_ShiftDown down-line
|
||||||
bindkeys keys_CtrlDown nop
|
bindkeys keys_CtrlDown nop
|
||||||
bindkeys keys_AltDown nop
|
bindkeys keys_AltDown nop
|
||||||
|
@ -251,15 +204,7 @@ function setup_keybinds() {
|
||||||
bindkeys keys_PageDown nop
|
bindkeys keys_PageDown nop
|
||||||
bindkeys keys_ShiftPageDown nop
|
bindkeys keys_ShiftPageDown nop
|
||||||
|
|
||||||
# atuin
|
bindkeys keys_CtrlR histdb-skim-widget
|
||||||
bindkey '^r' _atuin_search_widget
|
|
||||||
|
|
||||||
# fzf file and directory related expansions and functions
|
|
||||||
bindkey '\ef' fzf-select-file-or-dir
|
|
||||||
bindkey '\eF' fzf-select-file-or-dir-hidden
|
|
||||||
bindkey '\ed' fzf-select-dir
|
|
||||||
bindkey '\eD' fzf-select-dir-hidden
|
|
||||||
bindkey '\ec' fzf-cd
|
|
||||||
}
|
}
|
||||||
setup_keybinds
|
setup_keybinds
|
||||||
unfunction bindkeys
|
unfunction bindkeys
|
||||||
|
|
Loading…
Reference in a new issue