From 7c56e94b4fe659c10bfb87022d7537d1513f3ae3 Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Sat, 21 Sep 2024 14:12:08 -0700 Subject: [PATCH] Update from joey@joey-laptop: Polish fzf-bw and create function bwf (bw fuzzyfind) to use it. --- nix/home-manager/app/bitwarden/bitwarden.nix | 45 ++++++++++++++----- nix/home-manager/app/browser/zen.nix | 4 +- .../app/plasma-manager/plasma-manager.nix | 2 +- nix/home-manager/app/sh/sh.nix | 2 +- nix/home-manager/themes/cooper/theme.nix | 2 +- nix/home-manager/themes/temple/theme.nix | 2 +- nix/home-manager/users/joey.nix | 1 - nix/nixos/flatpak.nix | 2 +- nix/nixos/hardware-configuration.nix | 2 +- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/nix/home-manager/app/bitwarden/bitwarden.nix b/nix/home-manager/app/bitwarden/bitwarden.nix index 4171cedd..2ec4ddd2 100644 --- a/nix/home-manager/app/bitwarden/bitwarden.nix +++ b/nix/home-manager/app/bitwarden/bitwarden.nix @@ -5,24 +5,45 @@ jq wl-clipboard ( writeShellApplication { - name = "fzf-bw"; + name = "fzf-bw"; # { bwJson }: { itemPreviewJson } runtimeInputs = [ - jq - fzf wl-clipboard ( writeShellApplication { - name = "fzf-bw-preview"; + name = "fzf-bw-getUser"; # { itemJson }: { itemUsername } runtimeInputs = [ jq ]; - text = ''echo "$2" | jq -C --arg id "$1" '.[] | select(.id==$id) | {"user": "\(.login.username)", "password": "\(.login.password)", "name": "\(.name)"}' ''; + text = ''echo "$1" | jq -r '.user' ''; } ) - ]; + ( writeShellApplication { + name = "fzf-bw-getPass"; # { itemJson }: { itemPassword } + runtimeInputs = [ jq ]; + text = ''echo "$1" | jq -r '.password' ''; + } ) + ( writeShellApplication { + name = "fzf-bw-getItem"; # { itemUuid, bwJson }: { itemJson } + runtimeInputs = [ jq ]; + text = ''echo "$2" | jq -c --arg id "$1" '.[] | select(.id==$id) | {"user": "\(.login.username)", "password": "\(.login.password)", "name": "\(.name)"}' ''; + } ) + ( writeShellApplication { + name = "fzf-bw-selector"; # { bwJson }: { itemUuid } + runtimeInputs = [ jq fzf ]; + text = ''export json="$1"; echo "$json" | jq -r '.[].id' | fzf --height 30% --preview='fzf-bw-getItem {} "$json" | jq -C' --preview-window right --disabled --border --padding=1''; + excludeShellChecks = [ "SC2016" ]; + } ) + ] ; excludeShellChecks = [ "SC2016" ]; - text = ''export json="$1"; echo "$json" | jq -r '.[].id' | fzf --height 30% --preview='fzf-bw-preview {} "$json"' --preview-window right --disabled --border --padding=1 ''; + 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''; } ) - ( writeShellApplication { - name = "fzf-bw-copy"; - runtimeInputs = [ jq wl-clipboard ]; - text = ''json="$1"''; + ]; - programs.zsh.loginExtra = ''export $(bw unlock --passwordfile /home/joey/.bwtoken | grep export | sed 's/^\$\s//' | cut -d' ' -f2)''; + programs.zsh.loginExtra = '' + export $(bw unlock --passwordfile /home/joey/.bwtoken | grep export | sed 's/^\$\s//' | cut -d' ' -f2) + function bwf { search="$1"; fzf-bw "$(bw list items --search "$search")" } + ''; } + +# function { inputs }: { outputs } +# fzf-bw { bwJson }: { none } # copies user, pass to clipboard +# fzf-bw-getItem { itemUuid, bwJson }: { itemJson } +# fzf-bw-selector { bwJson }: { itemUuid } +# fzf-bw-getUser { itemJson }: { itemUsername } +# fzf-bw-getPass { itemJson }: { itemPassword } diff --git a/nix/home-manager/app/browser/zen.nix b/nix/home-manager/app/browser/zen.nix index d57aee2f..447e5508 100644 --- a/nix/home-manager/app/browser/zen.nix +++ b/nix/home-manager/app/browser/zen.nix @@ -1,6 +1,6 @@ -{ pkgs, ... }: +{ ... }: { services.flatpak.packages = [ { appId = "io.github.zen_browser.zen"; origin = "flathub"; } ]; -} \ No newline at end of file +} diff --git a/nix/home-manager/app/plasma-manager/plasma-manager.nix b/nix/home-manager/app/plasma-manager/plasma-manager.nix index 0136dbd9..1e1f070b 100644 --- a/nix/home-manager/app/plasma-manager/plasma-manager.nix +++ b/nix/home-manager/app/plasma-manager/plasma-manager.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ ... }: { programs.plasma = { enable = true; diff --git a/nix/home-manager/app/sh/sh.nix b/nix/home-manager/app/sh/sh.nix index 91d178af..de3d826d 100644 --- a/nix/home-manager/app/sh/sh.nix +++ b/nix/home-manager/app/sh/sh.nix @@ -22,7 +22,7 @@ ls = "eza"; fetch = "fastfetch"; neofetch = "fetch"; - fzf = ''fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"''; + find = ''fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"''; nu = "sudo nixos-rebuild switch --flake ~/Jafner.net/nix"; hmu = "home-manager switch -b bak --flake ~/Jafner.net/nix"; ngls = "nix-env --profile /nix/var/nix/profiles/system --list-generations"; diff --git a/nix/home-manager/themes/cooper/theme.nix b/nix/home-manager/themes/cooper/theme.nix index 841a1843..cc458afc 100644 --- a/nix/home-manager/themes/cooper/theme.nix +++ b/nix/home-manager/themes/cooper/theme.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ ... }: { stylix = { image = ./cooper.png; diff --git a/nix/home-manager/themes/temple/theme.nix b/nix/home-manager/themes/temple/theme.nix index 2bfd926e..85896251 100644 --- a/nix/home-manager/themes/temple/theme.nix +++ b/nix/home-manager/themes/temple/theme.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ ... }: { stylix = { image = ./temple.png; diff --git a/nix/home-manager/users/joey.nix b/nix/home-manager/users/joey.nix index c7890da7..13c0028c 100644 --- a/nix/home-manager/users/joey.nix +++ b/nix/home-manager/users/joey.nix @@ -20,7 +20,6 @@ # Desktop apps home.packages = with pkgs; [ - jq git kdePackages.kdeconnect-kde ]; diff --git a/nix/nixos/flatpak.nix b/nix/nixos/flatpak.nix index 293234e6..183a7b07 100644 --- a/nix/nixos/flatpak.nix +++ b/nix/nixos/flatpak.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ ... }: { services.flatpak.enable = true; diff --git a/nix/nixos/hardware-configuration.nix b/nix/nixos/hardware-configuration.nix index be44e271..99cf3923 100644 --- a/nix/nixos/hardware-configuration.nix +++ b/nix/nixos/hardware-configuration.nix @@ -1,7 +1,7 @@ # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. -{ config, lib, pkgs-stable, modulesPath, ... }: +{ config, lib, modulesPath, ... }: { imports =