Create export-video-list
script
Create a `export-video-list` script that exports all the video files on my external hard drive to a JSON file so I can easily see what videos I have without needing to get and plug in the drive. I can easily view it using `bat` or `jq` and combine it with `grep` to search for a specific video - e.g. `cat ~/video.json | grep -i nix` (`-i` makes the search case-insensitive).
This commit is contained in:
parent
13c83fb8b4
commit
ce5b4fa0a1
|
@ -11,6 +11,9 @@ let
|
|||
inherit (pkgs) writeShellApplication;
|
||||
|
||||
_timer = writeShellApplication (import ./scripts/_timer.nix);
|
||||
export-video-list = writeShellApplication (
|
||||
import ./scripts/export-video-list.nix { inherit pkgs; }
|
||||
);
|
||||
notetaker = writeShellApplication (import ./scripts/notetaker.nix);
|
||||
run = writeShellApplication (import ./scripts/run.nix { inherit pkgs; });
|
||||
t = writeShellApplication (import ./scripts/t.nix { inherit pkgs; });
|
||||
|
@ -68,5 +71,6 @@ with pkgs;
|
|||
++ pkgs.lib.optionals desktop [
|
||||
# Scripts.
|
||||
_timer
|
||||
export-video-list
|
||||
timer
|
||||
]
|
||||
|
|
|
@ -5,6 +5,9 @@ abbr daily="run create-daily next"
|
|||
abbr switch="run nixos nixedo switch"
|
||||
abbr sz="source ~/.config/zsh/.zshrc"
|
||||
|
||||
abbr evl="export-video-list"
|
||||
abbr vv="cat ~/Documents/videos.json"
|
||||
|
||||
abbr g="git"
|
||||
abbr ga="git add"
|
||||
abbr gap="git add -p"
|
||||
|
|
33
lib/shared/scripts/export-video-list.nix
Normal file
33
lib/shared/scripts/export-video-list.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
name = "export-video-list";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
jq
|
||||
tree
|
||||
udisks
|
||||
];
|
||||
|
||||
text = ''
|
||||
device_name="/dev/sda2"
|
||||
device_label="UNTITLED"
|
||||
|
||||
source_path="/run/media/opdavies/$device_label"
|
||||
|
||||
# If the source path doesn't exist, try mounting the device.
|
||||
if [[ ! -d "$source_path" ]]; then
|
||||
${pkgs.udisks}/bin/udisksctl mount -b "$device_name"
|
||||
fi
|
||||
|
||||
# Exit early if the source path still doesn't exist.
|
||||
if [[ ! -d "$source_path" ]]; then
|
||||
echo "Error: $source_path not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
output_file="$HOME/Documents/videos.json"
|
||||
|
||||
${pkgs.tree}/bin/tree -J "$source_path/Videos" | jq . > "$output_file"
|
||||
${pkgs.jq}/bin/jq . < "$output_file"
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue