aboutsummaryrefslogtreecommitdiffstats
path: root/modules/scripts
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar@proton.me>2026-04-14 18:32:28 +0530
committerArpit Chakladar <arpitchakladar@proton.me>2026-04-14 18:32:28 +0530
commitf7f5e84cf2bcae79e703bf5bdab39619c62ea198 (patch)
tree017dc5cca02f006ffa99b4740017c2ecd542e01d /modules/scripts
parent52a666f1979d68a84b3d5f59a30c90b549cb17a3 (diff)
downloadhome-manager-config-f7f5e84cf2bcae79e703bf5bdab39619c62ea198.tar.gz
home-manager-config-f7f5e84cf2bcae79e703bf5bdab39619c62ea198.zip
replaced rofi with a fzf script for launching desktop applications
Diffstat (limited to 'modules/scripts')
-rw-r--r--modules/scripts/default.nix82
-rw-r--r--modules/scripts/fzf-launcher.sh24
2 files changed, 56 insertions, 50 deletions
diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix
index 5242280..95d9298 100644
--- a/modules/scripts/default.nix
+++ b/modules/scripts/default.nix
@@ -4,19 +4,13 @@
pkgs,
...
}:
-
let
- # name: Script name
- # path: Path to script file
- # env: (Optional) Attribute set of environment variables { KEY = "VALUE"; }
+ shell =
+ if config.tools.zsh.enable then (lib.getExe config.programs.zsh.package) else "/usr/bin/env sh";
+
mkScript =
name: path: env:
let
- # Generate the shell shebang based on your config
- shell =
- if config.tools.zsh.enable then (lib.getExe config.programs.zsh.package) else "/usr/bin/env sh";
-
- # Convert the 'env' attribute set into a string of "export KEY='VALUE'" lines
envVars = lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n}=\"${toString v}\"") env);
in
pkgs.writeTextFile {
@@ -29,28 +23,26 @@ let
${builtins.readFile path}
'';
};
-in
-{
- config = {
- home.packages = [
- # Always included (pass empty set {} if no env vars needed)
- (mkScript "deep-clean" ./deep-clean.sh { })
- # Conditional scripts
- (lib.mkIf config.tools.fzf.enable (
- mkScript "fzf-launcher" ./fzf-launcher.sh {
- FZF = lib.getExe pkgs.fzf;
- }
- ))
+ scripts = {
+ deep-clean = mkScript "deep-clean" ./deep-clean.sh { };
+
+ fzf-launcher = lib.mkIf config.tools.fzf.enable (
+ mkScript "fzf-launcher" ./fzf-launcher.sh {
+ FZF = lib.getExe pkgs.fzf;
+ SETSID = "${pkgs.util-linux}/bin/setsid";
+ }
+ );
- (lib.mkIf (config.tools.ffmpeg.enable && config.tools.slop.enable) (
- mkScript "screen-recording" ./screen-recording.sh {
- FFMPEG = lib.getExe pkgs.ffmpeg-full;
- SLOP = lib.getExe pkgs.slop;
- }
- ))
+ screen-recording = lib.mkIf (config.tools.ffmpeg.enable && config.tools.slop.enable) (
+ mkScript "screen-recording" ./screen-recording.sh {
+ FFMPEG = lib.getExe pkgs.ffmpeg-full;
+ SLOP = lib.getExe pkgs.slop;
+ }
+ );
- (lib.mkIf
+ system-monitor =
+ lib.mkIf
(
config.tools.bottom.enable
&& config.tools.nvtop.enable
@@ -64,16 +56,30 @@ in
TMUX = lib.getExe pkgs.tmux;
KITTY = lib.getExe pkgs.kitty;
}
- )
- )
+ );
+
+ vpn-connect = lib.mkIf (config.tools.openvpn.enable && config.tools.fzf.enable) (
+ mkScript "vpn-connect" ./vpn-connect.sh {
+ FZF = lib.getExe pkgs.fzf;
+ OPENVPN = lib.getExe pkgs.openvpn;
+ SYSTEMD_RESOLVED = "${pkgs.openvpn}/libexec/update-systemd-resolved";
+ }
+ );
+ };
+in
+{
+ options.scripts = lib.mapAttrs (
+ name: _:
+ lib.mkOption {
+ type = lib.types.nullOr lib.types.package;
+ default = null;
+ description = "Derivation for the ${name} script, or null if disabled.";
+ }
+ ) scripts;
+
+ config = {
+ scripts = scripts;
- (lib.mkIf (config.tools.openvpn.enable && config.tools.fzf.enable) (
- mkScript "vpn-connect" ./vpn-connect.sh {
- FZF = lib.getExe pkgs.fzf;
- OPENVPN = lib.getExe pkgs.openvpn;
- SYSTEMD_RESOLVED = "${pkgs.openvpn}/libexec/update-systemd-resolved";
- }
- ))
- ];
+ home.packages = lib.filter (x: x != null) (lib.mapAttrsToList (_: v: lib.mkIf true v) scripts);
};
}
diff --git a/modules/scripts/fzf-launcher.sh b/modules/scripts/fzf-launcher.sh
index 592dd1e..79853f1 100644
--- a/modules/scripts/fzf-launcher.sh
+++ b/modules/scripts/fzf-launcher.sh
@@ -8,19 +8,15 @@ entries=""
for dir in "${DIRS[@]}"; do
[[ -d "$dir" ]] || continue
+
for f in "$dir"/*.desktop; do
[[ -f "$f" ]] || continue
grep -q "^NoDisplay=true" "$f" && continue
- grep -q "^Hidden=true" "$f" && continue
-
- # only keep Type=Application entries
+ grep -q "^Hidden=true" "$f" && continue
grep -q "^Type=Application" "$f" || continue
+ grep -q "^Terminal=true" "$f" && continue
- # skip terminal-only apps (no GUI window)
- grep -q "^Terminal=true" "$f" && continue
-
- # skip entries that are purely settings/mime handlers/background services
categories=$(grep -m1 "^Categories=" "$f" | cut -d= -f2-)
if [[ -n "$categories" ]]; then
echo "$categories" | grep -qE "(Settings|System|Screensaver|DesktopSettings|PackageManager)" && continue
@@ -31,21 +27,25 @@ for dir in "${DIRS[@]}"; do
[[ -z "$name" || -z "$exec" ]] && continue
- exec=$(echo "$exec" | sed 's/ %[fFuUickdDnNvm]//g')
+ # Remove field codes properly
+ exec=$(echo "$exec" | sed -E 's/ ?%[a-zA-Z]//g')
entries+="$name"$'\t'"$exec"$'\n'
done
done
-chosen=$(printf '%s' "$entries" | sort -f -t$'\t' -k1,1 | "$FZF" \
+entries=$(printf '%s' "$entries" | sort -fu -t$'\t' -k1,1)
+
+chosen=$(printf '%s' "$entries" | "$FZF" \
--prompt='Launch: ' \
--layout=reverse \
--info=inline \
- --with-nth=1 \
- --delimiter=$'\t')
+ --delimiter=$'\t' \
+ --with-nth=1)
[[ -z "$chosen" ]] && exit 0
exec_cmd=$(printf '%s' "$chosen" | cut -d$'\t' -f2)
-setsid bash -c "$exec_cmd" &>/dev/null &
+
+eval "$exec_cmd" &>/dev/null &
disown