Add scripts for tmux sessions and mail-sync.
This commit is contained in:
parent
61aa77b6ed
commit
6c179646e4
4 changed files with 101 additions and 1 deletions
|
@ -22,7 +22,7 @@ in
|
||||||
theme_sddm_midnight = callPackage ./sddm_midnight { };
|
theme_sddm_midnight = callPackage ./sddm_midnight { };
|
||||||
xdiskusage = callPackage ./xdiskusage { };
|
xdiskusage = callPackage ./xdiskusage { };
|
||||||
kanagawa = callPackage ./kanagawa { };
|
kanagawa = callPackage ./kanagawa { };
|
||||||
};
|
} // import ./scripts.nix { inherit pkgs; };
|
||||||
};
|
};
|
||||||
overlays = [
|
overlays = [
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
|
|
94
pkgs/scripts.nix
Normal file
94
pkgs/scripts.nix
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
tmux-sessions = pkgs.writeShellScriptBin "ts" ''
|
||||||
|
# use tmux provided through module configuration/global installation
|
||||||
|
# this is to ensure the right tmux version+configuration/plugins are loaded
|
||||||
|
if ! which tmux >/dev/null 2>&1; then
|
||||||
|
printf 'Unable to find tmux, make sure it is installed.'
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
SOURCES=(
|
||||||
|
~/Projects/
|
||||||
|
/persist/etc/nixos/
|
||||||
|
);
|
||||||
|
|
||||||
|
if [[ $# -eq 1 ]]; then
|
||||||
|
selected="$(${pkgs.coreutils-full}/bin/realpath "$1")";
|
||||||
|
if [[ ! -d "''${selected}" ]]; then
|
||||||
|
printf 'Not a directory: %s\n' "''${selected}";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
selected="$(
|
||||||
|
${pkgs.findutils}/bin/find "''${SOURCES[@]}" \
|
||||||
|
-type d \
|
||||||
|
-name ".git" \
|
||||||
|
-mindepth 1 \
|
||||||
|
-maxdepth 5 \
|
||||||
|
-prune 2>/dev/null \
|
||||||
|
| ${pkgs.gnused}/bin/sed 's;/\.git$;;' \
|
||||||
|
| ${pkgs.fzf}/bin/fzf
|
||||||
|
)";
|
||||||
|
fi;
|
||||||
|
|
||||||
|
if [[ -z "''${selected}" ]]; then
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
selected_name="$(${pkgs.coreutils-full}/bin/basename "''${selected}" | ${pkgs.coreutils-full}/bin/tr . _)";
|
||||||
|
|
||||||
|
if ! tmux has-session -t="''${selected_name}" 2> /dev/null; then
|
||||||
|
tmux new-session -ds "''${selected_name}" -c "''${selected}";
|
||||||
|
fi;
|
||||||
|
|
||||||
|
if [[ -z ''${TMUX} ]] && [[ -z ''${tmux_running} ]]; then
|
||||||
|
tmux -u attach -t="''${selected_name}";
|
||||||
|
exit 0;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
tmux switch-client -t "''${selected_name}";
|
||||||
|
exit 0;
|
||||||
|
'';
|
||||||
|
mail-sync = pkgs.writeShellScriptBin "mail-sync" ''
|
||||||
|
MBSYNC=$(${pkgs.procps}/bin/pgrep mbsync);
|
||||||
|
NOTMUCH=$(${pkgs.procps}/bin/pgrep notmuch);
|
||||||
|
if [ -f "''${HOME}/.config/pizauth.conf" ]; then
|
||||||
|
mapfile -t PIZAUTH_ACCOUNTS < <(${pkgs.gnugrep}/bin/grep -i account < "''${HOME}/.config/pizauth.conf" | ${pkgs.gnused}/bin/sed -E 's/^[^"]*"([^"]*).*$/\1/');
|
||||||
|
else
|
||||||
|
PIZAUTH_ACCOUNTS=();
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! which mbsync; then
|
||||||
|
printf 'Program mbsync not in path. Aborting!\n';
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Load Pizauth if it isn't running
|
||||||
|
if [ ''${#PIZAUTH_ACCOUNTS[@]} -gt 0 ] && [ -z "$(${pkgs.sysvtools}/bin/pidof pizauth)" ]; then
|
||||||
|
${pkgs.pizauth}/bin/pizauth server;
|
||||||
|
${pkgs.libsecret}/bin/secret-tool lookup pizauth keys | ${pkgs.gnupg}/bin/gpg -ad | ${pkgs.pizauth}/bin/pizauth restore;
|
||||||
|
sleep 5;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$MBSYNC" ] || [ -n "$NOTMUCH" ]; then
|
||||||
|
echo "Already running one instance of mbsync or notmuch. Exiting...";
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
printf 'Deleting messages tagged as *deleted*\n'
|
||||||
|
${pkgs.notmuch}/bin/notmuch search --format=text0 --output=files tag:deleted | ${pkgs.findutils}/bin/xargs -0 --no-run-if-empty rm -v;
|
||||||
|
|
||||||
|
if ! mbsync -a; then
|
||||||
|
for account in "''${PIZAUTH_ACCOUNTS[@]}"; do
|
||||||
|
printf 'Refreshing pizauth account "%s".\n' "''${account}";
|
||||||
|
${pkgs.pizauth}/bin/pizauth refresh "''${account}";
|
||||||
|
done;
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
${pkgs.notmuch}/bin/notmuch new;
|
||||||
|
exit $?;
|
||||||
|
'';
|
||||||
|
}
|
|
@ -12,5 +12,7 @@
|
||||||
(isync.override { withCyrusSaslXoauth2 = true; })
|
(isync.override { withCyrusSaslXoauth2 = true; })
|
||||||
mailutils
|
mailutils
|
||||||
pandoc # to convert messages
|
pandoc # to convert messages
|
||||||
|
# defined in ../pkgs/scripts.nix
|
||||||
|
mail-sync
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,4 +77,8 @@ lib.mkIf (lib.elem "tmux" config.machine.services) {
|
||||||
set -g set-titles-string "tmux: #S / #W"
|
set -g set-titles-string "tmux: #S / #W"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
# defined in ../pkgs/scripts.nix
|
||||||
|
tmux-sessions
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue