Move scripts to Nix files
Move the scripts I commonly use into Nix files managed by Home Manager. Some, like `mounter` and `unmounter` are desktop-only, but this can be addressed in a future commit to create per-host scripts or desktop/non-desktop scripts. This commit also removes a number of unused scripts that are either included in packages like `git-extras` or aren't used.
This commit is contained in:
parent
0b437adccc
commit
dfebe131a6
26 changed files with 194 additions and 323 deletions
45
modules/home-manager/cli/scripts/mounter.nix
Executable file
45
modules/home-manager/cli/scripts/mounter.nix
Executable file
|
@ -0,0 +1,45 @@
|
|||
{ pkgs }:
|
||||
|
||||
pkgs.writeShellApplication {
|
||||
name = "mounter";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
cryptsetup
|
||||
dmenu
|
||||
gawk
|
||||
libnotify
|
||||
util-linux
|
||||
];
|
||||
|
||||
text = ''
|
||||
lsblk_output="$(lsblk -rpo "uuid,name,type,size,label,mountpoint,mountpoints,fstype" | grep "part" | grep -Ev "/(boot|nix/store)")"
|
||||
partition_names="$(echo "$lsblk_output" | awk '{ printf "%s (%s)\n", $2, $4 }' )";
|
||||
|
||||
selected=$(echo "$partition_names" | dmenu -p "Select drive:" | awk '{ print $1 }')
|
||||
test -n "$selected"
|
||||
mount_device="$selected"
|
||||
|
||||
if sudo cryptsetup isLuks "$selected"; then
|
||||
luks_name="usb"
|
||||
|
||||
${"TERMINAL:-st"} -n floatterm -g 60x1 -e sudo cryptsetup open "$selected" "$luks_name"
|
||||
|
||||
mount_device="/dev/mapper/$luks_name"
|
||||
|
||||
test -b "/dev/mapper/$luks_name"
|
||||
fi
|
||||
|
||||
mount_point=$(echo -e "/mnt\n/media\n/run/media/$USER" | dmenu -p "Select mount point:")
|
||||
test -n "$mount_point"
|
||||
|
||||
sudo mkdir -p "$mount_point"
|
||||
|
||||
if sudo mount "$mount_device" "$mount_point"; then
|
||||
notify-send "Device mounted" "Mounted $selected at $mount_point."
|
||||
else
|
||||
notify-send "Mount failed" "Failed to mount $selected."
|
||||
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue