Update from joey@joey-laptop: Update fzf-bw to (mostly) working state. Init fzf-jq.

This commit is contained in:
Joey Hafner 2024-09-23 18:59:41 -07:00
parent 1c592faf33
commit 05947deacd
5 changed files with 45 additions and 15 deletions

1
nix/debug.txt Normal file
View File

@ -0,0 +1 @@
0.55.0 (v0.55.0)

Binary file not shown.

View File

@ -1,9 +1,10 @@
{ pkgs, ... }:
{ pkgs, pkgs-unstable, ... }:
{
home.packages = with pkgs; [
bitwarden-cli
jq
wl-clipboard
tmux
( writeShellApplication {
name = "fzf-bw"; # { bwJson }: { itemPreviewJson }
runtimeInputs = [
@ -25,19 +26,28 @@
} )
( writeShellApplication {
name = "fzf-bw-selector"; # { bwJson }: { itemUuid }
runtimeInputs = [ jq fzf ];
text = ''export json="$1"; echo "$json" | jq -r '.[].id' | fzf --height 33% --preview='fzf-bw-getItem {} "$json" | jq -C' --preview-window right,60% --disabled --border --padding=1'';
runtimeInputs = [ jq pkgs-unstable.fzf ];
text = ''export json="$1"; echo "$json" | jq -r '.[].id' | fzf --preview='fzf-bw-getItem {} "$json" | jq -C' --disabled '';
excludeShellChecks = [ "SC2016" ];
} )
( writeShellApplication {
name = "fzf-bw-selector-tmux"; # { bwJson }: { itemUuid }
runtimeInputs = [ jq pkgs-unstable.fzf ];
text = ''export json="$1"; echo "$json" | jq -r '.[].id' | fzf --tmux center,70% --preview='fzf-bw-getItem {} "$json" | jq -C' '';
excludeShellChecks = [ "SC2016" ];
} )
] ;
excludeShellChecks = [ "SC2016" ];
text = ''export json="$1"; itemJson="$(fzf-bw-getItem "$(fzf-bw-selector "$json")" "$json")"; echo "Username: (copied to clipboard)"; fzf-bw-getUser "$itemJson" | wl-copy; read -r; echo "Password: (copied to clipboard)"; fzf-bw-getPass "$itemJson" | wl-copy'';
# Todo: Gracefully handle Ctrl+C canceling, offer method to directly print or copy a password, implement fzf-tmux.
# Roadmap: sops integration to decrypt passwords as late as possible, window-manager hotkey for quicker use in graphical applications.
text = ''export json="$1"; itemJson="$(fzf-bw-getItem "$(fzf-bw-selector "$json")" "$json")"; echo -n "Username: (copied to clipboard)"; fzf-bw-getUser "$itemJson" | wl-copy; read -r; echo "Password: (copied to clipboard)"; fzf-bw-getPass "$itemJson" | wl-copy; exit 0'';
} )
];
programs.zsh.loginExtra = ''
export $(bw unlock --passwordfile /home/joey/.bwtoken | grep export | sed 's/^\$\s//' | cut -d' ' -f2)
export $(bw unlock --passwordfile /home/joey/.bwtoken | grep export | sed 's/^\$\s//' | cut -d' ' -f2) 2>/dev/null
function bwf { search="$1"; fzf-bw "$(bw list items --search "$search")" }
function bwf-popup { search="$1"; kitty --title fzf-bw --override remember_window_size=no --override initial_window_width=960 --override initial_window_height=300 fzf-bw "$(bw list items --search $search)" }
'';
}

View File

@ -0,0 +1,19 @@
{ pkgs, pkgs-unstable, ... }:
{
home.packages = with pkgs; [
jq
wl-clipboard
( writeShellApplication {
name = "fzf-jq"; # { bwJson }: { itemPreviewJson }
runtimeInputs = [ wl-clipboard jq ] ;
excludeShellChecks = [ "SC2016" ];
text = ''export json="$1"; itemJson="$(fzf-bw-getItem "$(fzf-bw-selector "$json")" "$json")"; echo -n "Username: (copied to clipboard)"; fzf-bw-getUser "$itemJson" | wl-copy; read -r; echo "Password: (copied to clipboard)"; fzf-bw-getPass "$itemJson" | wl-copy; exit 0'';
} )
];
programs.zsh.loginExtra = '' '';
}
# fzf-jq { jsonBody, searchByExp, itemPreviewExp }: { }
# summary: allows the user to interactively browse json objects
# details: takes a json object containing a list of objects, a jq expression which returns the list of objects on one line each, and a jq expression which returns only the object currently selected

View File

@ -7,6 +7,13 @@
enable = true;
};
## Tmux
programs.tmux = {
enable = true;
newSession = true;
shell = "$HOME/.nix-profile/bin/zsh";
};
# Shell
## Zsh
programs.zsh = {
@ -17,7 +24,6 @@
syntaxHighlighting.enable = true;
shellAliases = {
bat = "bat --paging=never --color=always";
cat = "bat";
fd = "fd -Lu";
ls = "eza";
fetch = "fastfetch";
@ -63,7 +69,7 @@
home.packages = with pkgs; [
fastfetch
tree btop
bat fd eza fzf-git-sh tmux
bat fd eza fzf-git-sh
wl-clipboard
pkgs-unstable.fzf
];
@ -108,11 +114,5 @@
programs.fzf = {
enable = true;
package = pkgs-unstable.fzf;
};
## tmux
programs.tmux = {
enable = true;
};
};
}