diff --git a/home/programs/xmonad/default.nix b/home/programs/xmonad/default.nix index 874ae20e..a50f538f 100644 --- a/home/programs/xmonad/default.nix +++ b/home/programs/xmonad/default.nix @@ -129,18 +129,6 @@ in type = types.str; description = "Command to spawn the default terminal emulator"; }; - - wiki = { - command = mkOption { - type = types.str; - description = "Command to spawn the default wiki app"; - }; - wmClassName = mkOption { - type = types.str; - description = "Window manager class name retrieved via `xprop` utility"; - }; - }; - }; }; diff --git a/home/programs/xmonad/xmonad.hs.nix b/home/programs/xmonad/xmonad.hs.nix index 221e73f4..60dbd36e 100644 --- a/home/programs/xmonad/xmonad.hs.nix +++ b/home/programs/xmonad/xmonad.hs.nix @@ -91,8 +91,8 @@ pkgs.writeText "xmonad.hs" '' h = (3/4) x = center w y = center h - spawnWiki = "${cfg.wiki.command}" - findWiki = className =? "${cfg.wiki.wmClassName}" + spawnWiki = myTerminal ++ " -t wiki -e nb --interactive ls" + findWiki = title =? "wiki" manageWiki = customFloating $ W.RationalRect x y w h where w = (4/5) diff --git a/home/roles/desktop/xmonad/default.nix b/home/roles/desktop/xmonad/default.nix index 4f973dff..cadd106c 100644 --- a/home/roles/desktop/xmonad/default.nix +++ b/home/roles/desktop/xmonad/default.nix @@ -60,10 +60,6 @@ in command = mkDefault "1password"; wmClassName = mkDefault "1Password"; }; - wiki = { - command = mkDefault "joplin-desktop"; - wmClassName = mkDefault "Joplin"; - }; }; }; }; diff --git a/home/roles/web/default.nix b/home/roles/web/default.nix index 95ac59e5..23833c7c 100644 --- a/home/roles/web/default.nix +++ b/home/roles/web/default.nix @@ -38,7 +38,6 @@ in _1password _1password-gui bind - joplin-desktop wget thunderbird diff --git a/home/users/christian/shell/default.nix b/home/users/christian/shell/default.nix index 5d072ee6..4dc8f8dc 100644 --- a/home/users/christian/shell/default.nix +++ b/home/users/christian/shell/default.nix @@ -51,6 +51,7 @@ in gron htop killall + nb neofetch pandoc texlive.combined.scheme-small @@ -67,7 +68,6 @@ in programs = { ssh = import ./ssh.nix; - zsh = import ./zsh.nix; bat.enable = true; exa.enable = true; diff --git a/home/users/christian/shell/zsh.nix b/home/users/christian/shell/zsh.nix deleted file mode 100644 index 3a2e74a2..00000000 --- a/home/users/christian/shell/zsh.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ - enable = true; - enableAutosuggestions = true; - enableCompletion = true; - enableSyntaxHighlighting = true; - autocd = true; - dotDir = ".config/zsh"; - dirHashes = { - bb = "/mnt/bluecare/bluecare"; - bh = "/mnt/bluecare/home"; - bt = "/mnt/bluecare/transfer"; - d = "$HOME/Documents"; - dl = "$HOME/Downloads"; - hh = "/mnt/home/home"; - hm = "/mnt/home/music"; - hp = "/mnt/home/photo"; - ht = "/mnt/home/public"; - hv = "/mnt/home/video"; - p = "$HOME/Pictures"; - usb = "/run/media/chr"; - v = "$HOME/Videos"; - }; - history = - let - historySize = 1000000; - in - { - expireDuplicatesFirst = true; - extended = true; - ignoreDups = true; - ignoreSpace = true; - path = "$ZDOTDIR/.zsh_history"; - save = historySize; - share = true; - size = historySize; - }; - shellGlobalAliases = { - "..." = "../.."; - "...." = "../../.."; - "....." = "../../../.."; - "......" = "../../../../.."; - "......." = "../../../../../.."; - "........" = "../../../../../../.."; - G = "| grep"; - UUID = "$(uuidgen | tr -d \\n)"; - }; -} diff --git a/home/users/christian/shell/zsh/completions/_nb b/home/users/christian/shell/zsh/completions/_nb new file mode 100644 index 00000000..fe6093d6 --- /dev/null +++ b/home/users/christian/shell/zsh/completions/_nb @@ -0,0 +1,174 @@ +#compdef nb +############################################################################### +# __ _ +# \ \ _ __ | |__ +# \ \ | '_ \| '_ \ +# / / | | | | |_) | +# /_/ |_| |_|_.__/ +# +# [nb] Command line and local web note-taking, bookmarking, and archiving with +# plain text data storage, encryption, filtering and search, pinning, #tagging, +# Git-backed versioning and syncing, Pandoc-backed conversion, global and local +# notebooks, customizable color themes, [[wiki-style linking]], plugins, and +# more in a single portable, user-friendly script. +# +# https://github.com/xwmx/nb +############################################################################### +_nb_subcommands() { + # _nb_cache_completions() + # + # Usage: + # _nb_cache_completions + # + # Description: + # Cache completions for `nb`. Generating completions can be slow and + # native shell caching doesn't appear to help. + _nb_cache_completions() { + local _cache_path="${1:-}" + + [[ -z "${_cache_path:-}" ]] && return 0 + + # Remove outdated cache files. + + local _base_cache_path="${_cache_path%-*}" + + local __suffix= + for __suffix in "zsh" "v1" + do + if [[ -e "${_base_cache_path:?}-${__suffix:?}" ]] + then + \rm -f "${_base_cache_path:?}-${__suffix:?}" + fi + done + + # Rebuild completion cache. + + local _commands= + IFS=$'\n' _commands=($(nb subcommands)) + + local _notebooks= + IFS=$'\n' _notebooks=($(nb notebooks --names --no-color --unarchived)) + + local _completions=() + IFS=$'\n' _completions=(${_commands[@]}) + + local _commands_cached= + local _notebooks_cached= + + if [[ -e "${_cache_path}" ]] + then + local _counter=0 + + local __line= + while IFS= read -r __line + do + _counter=$((_counter+1)) + + if [[ "${_counter}" == 1 ]] + then + _commands_cached="${__line}" + elif [[ "${_counter}" == 2 ]] + then + _notebooks_cached="${__line}" + else + break + fi + done < "${_cache_path}" + fi + + if [[ "${_commands_cached}" != "${_commands[*]:-}" ]] || + [[ "${_notebooks_cached}" != "${_notebooks[*]:-}" ]] + then + # Construct : completions. + local __notebook= + for __notebook in "${_notebooks[@]}" + do + local __command= + for __command in "${_commands[@]}" + do + if [[ -n "${__notebook:-}" ]] && + [[ -n "${__command:-}" ]] + then + _completions+=("${__notebook}:${__command}") + fi + done + done + + local _directory_path= + _directory_path="$(dirname "${_cache_path}")" + + mkdir -p "${_directory_path}" + + if [[ -f "${_cache_path:?}" ]] + then + \rm -f "${_cache_path:?}" + fi + + touch "${_cache_path:?}" + + { + (IFS=$' '; printf "%s\\n" "${_commands[*]}") + (IFS=$' '; printf "%s\\n" "${_notebooks[*]}") + printf "%s\\n" "${_completions[@]}" + } >> "${_cache_path}" + fi + } + + local _nb_dir= + _nb_dir="$(nb env | grep 'NB_DIR' | cut -d = -f 2)" + + if [[ -z "${_nb_dir:?}" ]] || + [[ ! -e "${_nb_dir}" ]] + then + return 0 + elif [[ -L "${_nb_dir}" ]] + then + if hash "realpath" 2>/dev/null + then + _nb_dir="$(realpath "${_nb_dir}")" + else + _nb_dir="$(readlink "${_nb_dir}")" + fi + fi + + if [[ ! -d "${_nb_dir}" ]] + then + return 0 + fi + + local _cache_path="${_nb_dir:?}/.cache/nb-completion-cache-v2" + local _completions_cached=() + + if [[ ! -e "${_cache_path}" ]] + then + _nb_cache_completions "${_cache_path}" + fi + + if [[ -e "${_cache_path}" ]] + then + local _counter=0 + + local __line= + while IFS= read -r __line + do + _counter=$((_counter+1)) + + if [[ "${_counter}" -gt 2 ]] + then + _completions_cached+=("${__line}") + fi + done < "${_cache_path}" + + (_nb_cache_completions "${_cache_path}" &) + fi + + if [[ "${?}" -eq 0 ]] + then + compadd -- "${_completions_cached[@]}" + return 0 + else + return 1 + fi +} + +_nb_subcommands "$@" diff --git a/home/users/christian/shell/zsh/default.nix b/home/users/christian/shell/zsh/default.nix new file mode 100644 index 00000000..b2825b6e --- /dev/null +++ b/home/users/christian/shell/zsh/default.nix @@ -0,0 +1,62 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + home = { + file = { + "${config.programs.zsh.dotDir}/completions".source = ./completions; + }; + }; + + programs.zsh = { + enable = true; + enableAutosuggestions = true; + enableCompletion = true; + enableSyntaxHighlighting = true; + autocd = true; + dotDir = ".config/zsh"; + dirHashes = { + bb = "/mnt/bluecare/bluecare"; + bh = "/mnt/bluecare/home"; + bt = "/mnt/bluecare/transfer"; + d = "$HOME/Documents"; + dl = "$HOME/Downloads"; + hh = "/mnt/home/home"; + hm = "/mnt/home/music"; + hp = "/mnt/home/photo"; + ht = "/mnt/home/public"; + hv = "/mnt/home/video"; + p = "$HOME/Pictures"; + usb = "/run/media/chr"; + v = "$HOME/Videos"; + }; + history = + let + historySize = 1000000; + in + { + expireDuplicatesFirst = true; + extended = true; + ignoreDups = true; + ignoreSpace = true; + path = "$ZDOTDIR/.zsh_history"; + save = historySize; + share = true; + size = historySize; + }; + initExtraBeforeCompInit = '' + fpath=(~/.zsh/completion $fpath) + ''; + shellGlobalAliases = { + "..." = "../.."; + "...." = "../../.."; + "....." = "../../../.."; + "......" = "../../../../.."; + "......." = "../../../../../.."; + "........" = "../../../../../../.."; + G = "| grep"; + UUID = "$(uuidgen | tr -d \\n)"; + }; + }; +}