Fzgo updates

This commit is contained in:
Thomas Avé 2025-01-28 01:20:00 +01:00
parent 9b5a5b7de7
commit cc74981997
7 changed files with 168 additions and 146 deletions

View File

@ -47,8 +47,14 @@ let
'');
};
};
in
{
fzgo_paths = [
"/home/server/.dotfiles"
"/home/server/Containers"
"/home/server/Workspace"
"/home/server/Storage/Thomas"
"/home/server/Storage/Shared"
];
in {
home.username = "server";
home.homeDirectory = "/home/server";
nix = {
@ -63,7 +69,8 @@ in
imports = [
(import ./utils/common.nix { inherit inputs config pkgs; })
(import ./utils/services.nix { inherit pkgs; scripts = scripts; })
(import ./utils/services.nix { inherit pkgs scripts; })
(import ./utils/fzgo_links.nix { inherit config pkgs fzgo_paths; })
./ssh
];
programs.ssh.matchBlocks."*".identityFile = "/home/server/.secrets/SSH/Mallorea/id_ed25519";
@ -73,9 +80,4 @@ in
LANG = "en_US.UTF-8";
XDG_RUNTIME_DIR = "/run/user/$(id -u)";
};
programs.zsh.initExtra = pkgs.lib.mkForce ''
LOCAL_SEARCH_DIRS=(~/.dotfiles/ ~/Containers ~/Workspace ~/Storage/Thomas ~/Storage/Shared)
REMOTE_SEARCH_DIRS=()
'';
}

View File

@ -1,9 +1,14 @@
{ inputs, config, pkgs, ... }:
let
fzgo_paths = [
"/home/user/.dotfiles"
];
in
{
imports = [
(import ./utils/common.nix { inherit inputs config pkgs; })
(import ./utils/python.nix { inherit inputs config pkgs; })
(import ./utils/fzgo_links.nix { inherit config pkgs fzgo_paths; })
./ssh
];

12
home/utils/fzgo_links.nix Normal file
View File

@ -0,0 +1,12 @@
{ config, pkgs, fzgo_paths }:
let
mkLink = source_path: file_type: {
"${source_path}_${file_type}" = {
source = config.lib.file.mkOutOfStoreSymlink source_path;
target = "/home/user/.config/fzgo/entries/${file_type}/${pkgs.lib.strings.replaceStrings [ "/" ] [ "|" ] source_path}";
};
};
mkLinks = source_path: (mkLink source_path "d") // (mkLink source_path "f");
in {
home.file = pkgs.lib.mkMerge (map mkLinks fzgo_paths);
}

View File

@ -19,8 +19,7 @@
PDF_VIEWER = "evince";
GPULAB_CERT = "${config.xdg.configHome}/../.secrets/GPULab/certificate.pem";
GPULAB_DEV = "False";
GCC_COLORS =
"error = '01;31:warning = '01;35:note = '01;36:caret = '01;32:locus = '01:quote = '01'";
GCC_COLORS = "error = '01;31:warning = '01;35:note = '01;36:caret = '01;32:locus = '01:quote = '01'";
ARCHFLAGS = "-arch x86_64";
TERM = "screen-256color";
PYTHONDONTWRITEBYTECODE = "1";
@ -56,45 +55,29 @@
enableCompletion = true;
syntaxHighlighting.enable = false;
autosuggestion.enable = true;
initExtra = ''
LOCAL_SEARCH_DIRS=(~/.dotfiles/)
REMOTE_SEARCH_DIRS=(
~/Workspace/Trackbox/Branches/
~/Workspace/Trackbox/Repositories/
~/Workspace/Trackbox/Resources/
~/Workspace/Trackbox/Docker/
~/Workspace/University/PhD/Thesis/
/home/server/Storage/Shared/
/home/server/Storage/Thomas/
)
export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH
'';
initExtra = ''export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH'';
initExtraFirst = ''
ZVM_VI_INSERT_ESCAPE_BINDKEY=jj
source ${./files/waypipe.zsh}
source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
source ${./files/p10k.zsh}
source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
source ${./files/functions.zsh}
function zvm_after_init() {
source ${./files/term.zsh}
source ${./files/completion.zsh}
if [ -n "\$\{commands[fzf-share]\}" ]; then
source "$(fzf-share)/key-bindings.zsh"
source "$(fzf-share)/completion.zsh"
fi
source ${./files/keys.zsh}
eval "$(direnv hook zsh)"
export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH
}
function run() {
NIXPKGS_ALLOW_UNFREE=1 nix run --impure "nixpkgs#$1" -- "''${@:2}"
}
function o() {
${pkgs.handlr-regex}/bin/handlr open $@ < /dev/null &> /dev/null & disown
}
ZVM_VI_INSERT_ESCAPE_BINDKEY=jj
source ${./files/waypipe.zsh}
source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
source ${./files/p10k.zsh}
source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
source ${./files/functions.zsh}
source ${./files/fzgo.zsh}
function zvm_after_init() {
source ${./files/term.zsh}
source ${./files/completion.zsh}
if [ -n "\$\{commands[fzf-share]\}" ]; then
source "$(fzf-share)/key-bindings.zsh"
source "$(fzf-share)/completion.zsh"
fi
source ${./files/keys.zsh}
eval "$(direnv hook zsh)"
export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH
}
function o() {
${pkgs.handlr-regex}/bin/handlr open $@ < /dev/null &> /dev/null & disown
}
'';
shellAliases = {
@ -114,14 +97,10 @@
python = "python3";
vim = "nvim";
v = ''echo $(pwd) > /tmp/oil_dir && nvim -c ':lua require("oil").open()' && cd "$(cat /tmp/oil_dir 2> /dev/null || pwd)"'';
cpr =
"rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1";
mvr =
"rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1 --remove-source-files";
rg =
"rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
ag =
"rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
cpr = "rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1";
mvr = "rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1 --remove-source-files";
rg = "rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
ag = "rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
reset = "tput reset";
};
history.size = 10000000;

View File

@ -1,89 +1,3 @@
function cd_to() {
setopt localoptions pipefail no_aliases 2> /dev/null
local dir=$1
if [[ -z "$dir" ]]; then
zle redisplay
return 0
fi
zle push-line # Clear buffer. Auto-restored on next prompt.
cd $dir
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
}
function find_local() {
fd . -t $1 | fzgo
}
function find_global() {
file_type=$1
mkdir -p ~/.cache/fzgo_paths
FZGO_CACHE=~/.cache/fzgo_paths/$file_type
FZGO_RECENTS=~/.cache/fzgo_paths/recents_$file_type
if [ -f $FZGO_CACHE ]; then
if [ $(stat -c %Y $FZGO_CACHE) -lt $(date +%s -d '-1 day') ]; then
rm $FZGO_CACHE
fi
fi
if [ ! -f $FZGO_CACHE ]; then
PATHS=""
for i in "$LOCAL_SEARCH_DIRS[@]"; do
if [ -d "$i" ]; then
PATHS="$PATHS\n$i\n$(fd . $i -t $file_type)"
fi
done
for i in "$REMOTE_SEARCH_DIRS[@]"; do
if [ -d "$i" ]; then
PATHS="$PATHS\n$i\n$(ssh mallorea fd . \"$i\" -t $file_type -d 15)"
fi
done
echo "$PATHS" > $FZGO_CACHE
fi
touch $FZGO_RECENTS
file="$(cat $FZGO_RECENTS $FZGO_CACHE | awk '!x[$0]++' | fzgo)"
echo "$file" | cat - $FZGO_RECENTS | awk '!x[$0]++' > /tmp/fzgo_paths_recents_$file_type && mv /tmp/fzgo_paths_recents_$file_type $FZGO_RECENTS
echo "$file"
}
function open_path() {
file_type=$1
search_fn=$2
selection="$($search_fn $file_type)"
if [ "$selection" = "" ]; then
zle reset-prompt
return
fi
if [ "$LBUFFER" = "" ]; then
if [ "$file_type" = "d" ]; then
cd_to "$selection"
else
selection=$(realpath "$selection")
parent=$(dirname "$selection")
cd_to "$parent"
nvim "$selection"
fi
else
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$selection\""
zle reset-prompt
fi
}
function open_global_path_d() { open_path d find_global }
function open_global_path_f() { open_path f find_global }
function open_local() { open_path f find_local }
function register_key() {
zle -N $2
bindkey "^$1" $2
bindkey -M emacs "^$1" $2
bindkey -M vicmd "^$1" $2
bindkey -M viins "^$1" $2
}
function push() {
git add -A
if [ -z "$*" ]; then
@ -93,3 +7,7 @@ function push() {
fi
git push
}
function run() {
NIXPKGS_ALLOW_UNFREE=1 nix run --impure "nixpkgs#$1" -- "''${@:2}"
}

106
home/zsh/files/fzgo.zsh Normal file
View File

@ -0,0 +1,106 @@
local function cd_to() {
setopt localoptions pipefail no_aliases 2> /dev/null
local dir=$1
if [[ -z "$dir" ]]; then
zle redisplay
return 0
fi
zle push-line # Clear buffer. Auto-restored on next prompt.
cd $dir
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
}
local function get_entries() {
file_type=$1
if [ ! -d "$XDG_CONFIG_HOME/fzgo/entries" ]; then
return
fi
for entry in "$XDG_CONFIG_HOME/fzgo/entries/$file_type"/*; do
# If the file is a symlink to a directory, we want to list the directory
if [ -L "$entry" ]; then
target=$(realpath "$entry")
if [ -d "$target" ]; then
fd . "$target" -t "$file_type"
fi
else
cat "$entry"
fi
done
}
function fzgo_update_cache() {
for file_type_dir in "$XDG_CONFIG_HOME/fzgo/entries"/*; do
mkdir -p "$XDG_CACHE_HOME/fzgo/entries"
for entry in "$file_type_dir"/*; do
file_type=$(basename "$file_type_dir")
mkdir -p "$XDG_CACHE_HOME/fzgo/entries/$file_type"
# If the file is a symlink to a directory, we want to list the directory
if [ -L "$entry" ]; then
target=$(realpath "$entry")
if [ -d "$target" ]; then
out_file="$(echo "$target" | sed 's\/\|\g')"
out_file="$XDG_CACHE_HOME/fzgo/entries/$file_type/$out_file"
mkdir -p "$(dirname \"$out_file\")"
fd . "$target" -t "$file_type" > "$out_file"
fi
fi
done
done
}
local function find_global() {
file_type=$1
FZGO_RECENTS=$XDG_CACHE_HOME/fzgo/recent_paths_$file_type
mkdir -p $(dirname $FZGO_RECENTS)
touch $FZGO_RECENTS
FZGO_RECENT_ENTRIES=$(cat $FZGO_RECENTS)
FZGO_ENTRIES=$(get_entries $file_type)
file="$(echo $FZGO_RECENT_ENTRIES'\n'$FZGO_ENTRIES | awk '!x[$0]++' | fzgo)"
echo "$file" | cat - $FZGO_RECENTS | awk '!x[$0]++' > /tmp/fzgo_paths_recents_$file_type && mv /tmp/fzgo_paths_recents_$file_type $FZGO_RECENTS
echo "$file"
}
local function find_local() {
fd . -t $1 | fzgo
}
local function open_path() {
file_type=$1
search_fn=$2
selection="$($search_fn $file_type)"
if [ "$selection" = "" ]; then
zle reset-prompt
return
fi
if [ "$LBUFFER" = "" ]; then
if [ "$file_type" = "d" ]; then
cd_to "$selection"
else
selection=$(realpath "$selection")
parent=$(dirname "$selection")
cd_to "$parent"
$EDITOR "$selection"
fi
else
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$selection\""
zle reset-prompt
fi
}
function fzgo_global_d() { open_path d find_global }
function fzgo_global_f() { open_path f find_global }
function fzgo_local_f() { open_path f find_local }
function fzgo_register_key() {
zle -N $2
bindkey "^$1" $2
bindkey -M emacs "^$1" $2
bindkey -M vicmd "^$1" $2
bindkey -M viins "^$1" $2
}

View File

@ -39,6 +39,6 @@ bindkey -M vicmd "^R" fzf-history-widget
bindkey -M viins "^R" fzf-history-widget
bindkey -M emacs "^R" fzf-history-widget
register_key "T" open_global_path_d
register_key "E" open_global_path_f
register_key "W" open_local
fzgo_register_key "T" fzgo_global_d
fzgo_register_key "E" fzgo_global_f
fzgo_register_key "W" fzgo_local_f