Moved scripts to the overlay folder to be used as packages

All scripts have been moved to the overlay folder in the top level directory

Overlay is now instantiated per configuration to make use of the host variable
This commit is contained in:
2024-11-16 03:42:07 -05:00
parent 2a2263d4cb
commit 8c007c3915
27 changed files with 200 additions and 175 deletions

View File

@@ -0,0 +1,18 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "icanhazip";
runtimeInputs = with pkgs; [ iproute2 curl gawk coreutils ];
text = ''
if [ $# -eq 0 ]; then
echo "Public IP: $(curl -s icanhazip.com -4)"
ip route | awk '/default/ {print "Default Gateway: " $3} /src/ {print "Local IP: " $9}' | head -n 2
else case $1 in
"-p" ) echo "Public IP: $(curl -s icanhazip.com -4)";;
"-d" ) ip route | awk '/default/ {print $3}';;
"-l" ) ip route | awk '/src/ {print $9}';;
* ) echo "Options: -p, -d or -l for public ip, default gateway, and local ip respectively"; echo "i.e. icanhazip -p"
esac
fi
'';
}

View File

@@ -0,0 +1,9 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "invoke";
text = ''
cmd="$1"
shift
nix run nixpkgs#"$cmd" -- "$@"
'';
}

View File

@@ -0,0 +1,27 @@
{ pkgs, }:
pkgs.writeShellApplication {
name = "runbg";
runtimeInputs = with pkgs; [
coreutils # Provides `basename`, `which`, etc.
bash # Provides the Bash shell
util-linux # Provides `tty`
];
text = ''
#!/usr/bin/env bash
[ $# -eq 0 ] && { # $# is number of args
echo "$(basename "$0"): missing command" >&2
exit 1
}
prog="$(which "$1")" # see below
[ -z "$prog" ] && {
echo "$(basename "$0"): unknown command: $1" >&2
exit 1
}
shift # remove $1, now $prog, from args
tty -s && exec </dev/null # if stdin is a terminal, redirect from null
tty -s <&1 && exec >/dev/null # if stdout is a terminal, redirect to null
tty -s <&2 && exec 2>&1 # stderr to stdout (which might not be null)
"$prog" "$@" & # $@ is all args
'';
}

View File

@@ -0,0 +1,12 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "splash";
runtimeInputs = with pkgs; [ lolcat toilet coreutils ];
text = ''
echo "NixOS kernel ver. $(uname -a | awk '{print $3}') x86_64 GNU/Linux"
date +"%A %B %-d %Y"
echo
echo " NixOS" | toilet -f 3d | lolcat -S 25
echo
'';
}

View File

@@ -0,0 +1,95 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "toolbelt";
runtimeInputs = with pkgs; [
cliphist
fzf
ripgrep
gawk
wl-clipboard
hyprland
alsa-utils
btop
coreutils
];
text = ''
cliphistory() {
selection=$(cliphist list | fzf --preview="
index=\$(echo {} | awk '{print \$1}'); \
mime=\$(cliphist decode \$index | file -i -); \
if echo \"\$mime\" | grep -q 'image'; then \
echo \$(cliphist list | rg \"^\$index\" | cut -d ' ' -f 2- | fmt -w 30); \
else \
cliphist decode \"\$index\" | fmt -w 30; \
fi" --prompt="> " | awk '{print $1}')
[ -z "$selection" ] && return 1
cliphist decode "$selection" | wl-copy
}
btop_cmd() {
if [ "$(cat /etc/hostname)" = "oganesson" ]; then
hyprctl dispatch resizeactive 20% 155% &&
moveonscreen --center &&
btop &&
hyprctl dispatch resizeactive exact 40% 25% &&
moveonscreen
else
hyprctl dispatch resizeactive exact 60% 68% &&
moveonscreen --center &&
btop &&
hyprctl dispatch resizeactive exact 40% 25% &&
moveonscreen
fi
}
running=true
declare -A commands=(
["Change Wallpaper"]="moveonscreen --center && if chpaper; then running=false; else moveonscreen; fi"
["Change System Color Scheme"]="hyprctl dispatch resizeactive 10% 80% && moveonscreen --center && if chscheme; then running=false; else hyprctl dispatch resizeactive exact 40% 25% && moveonscreen; fi"
["Open System Monitor"]="btop_cmd"
["Open Volume Controls"]="hyprctl dispatch resizeactive 10% 80% && moveonscreen --center && alsamixer && hyprctl dispatch resizeactive exact 40% 25% && moveonscreen"
["Open Keyring"]="hyprctl dispatch resizeactive -300 0 && moveonscreen && if keyring; then running=false; else hyprctl dispatch resizeactive exact 40% 25% && moveonscreen; fi"
["View Clipboard History"]="hyprctl dispatch resizeactive 45% 120% && moveonscreen --center && if cliphistory;then running=false; else hyprctl dispatch resizeactive exact 40% 25% && moveonscreen; fi"
)
ordered_commands=(
"Open Keyring"
"Open System Monitor"
"Open Volume Controls"
"Change Wallpaper"
"Change System Color Scheme"
"View Clipboard History"
)
# Use fzf to select a command with preview
while $running; do
selected_command=$(printf "%s\n" "''${ordered_commands[@]}" | fzf --preview="
cleaned_key=\$(echo {} | tr -d \"'\"); \
echo \"Cleaned key: \$cleaned_key\"; \
declare -A descriptions=(
[\"Change Wallpaper\"]=\"Choose a wallpaper to switch to from the assets/wallpapers folder in the system flake directory. Requires rebuilding the system and restarting hyprpaper.\"
[\"Change System Color Scheme\"]=\"Changes the base16 color scheme used by stylix to color system applications.\"
[\"Open System Monitor\"]=\"Opens a btop window.\"
[\"Open Volume Controls\"]=\"Opens alsamixer.\"
[\"Open Keyring\"]=\"Opens a fuzzy finder with all of the paths held in ~/.password-store. Selecting one uses pass to copy that password to the clipboard. Password is cleared from clipboard after 45 seconds, and isn't saved to clipboard history.\"
[\"View Clipboard History\"]=\"Opens clipboard history. Selecting an item copies it to the clipboard.\"
); \
if [[ -v descriptions[\$cleaned_key] ]]; then \
clear; \
echo \''${descriptions[\$cleaned_key]} | fmt -w 28; \
else \
clear; \
echo \"No description available\"; \
fi" --prompt="> ")
#Execute the selected command if selection is not empty
if [[ -n $selected_command ]]; then
eval "''${commands[$selected_command]}"
else
running=false
fi
done
'';
}

View File

@@ -0,0 +1,40 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "viconf";
runtimeInputs = with pkgs; [ coreutils fd ripgrep fzf ];
text = ''
#!/usr/bin/env bash
[ ! $# -eq 1 ] && echo "Usage: viconf <*.nix>" && exit 1
results=$(find "$FLAKEPATH" -wholename "*$1*" -exec find {} \; | sort | uniq | rg '\.nix$')
numresults=$(echo "$results" | wc -l)
[ "$numresults" -eq 0 ] && echo "$1 not found in \$FLAKEPATH" && exit 1
if [ "$numresults" -gt 1 ]; then
# cut up the paths to give shorter path names to fuzzy finder
results_prefix=$(echo "$results" | tail -n 1 | cut -d'/' -f-3)
results=$(echo "$results" | cut -d'/' -f4-)
results=$(echo "$results" | grep "$1")
file=$(echo "$results" | tr ' ' '\n' | fzf)
file="$results_prefix/$file"
# Check if the file contains any non-UTF-8 characters
if grep --color='auto' -P -q "[^\x00-\x7F]" "$file"; then
NIXD_FLAGS="--semantic-tokens=false" nvim "$results_prefix"/"$file"
else
nvim "$file"
fi
else
# Check if the file contains any non-UTF-8 characters
if grep --color='auto' -P -q "[^\x00-\x7F]" "$results"; then
NIXD_FLAGS="--semantic-tokens=false" nvim "$results"
else
nvim "$results"
fi
fi
'';
}

View File

@@ -0,0 +1,35 @@
{ pkgs ? import <nixpkgs> { } }:
let
nixpkgs_toplevel = pkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "63dacb46bf939521bdc93981b4cbb7ecb58427a0";
hash = "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=";
};
in pkgs.writeShellApplication {
name = "vipkg";
runtimeInputs = with pkgs; [ coreutils fd ripgrep fzf ];
text = ''
[ ! $# -eq 1 ] && echo "Usage: vipkg <nixpkgs package name>" && exit 1
results=$(find "${nixpkgs_toplevel}/pkgs" -wholename "*$1*" -exec find {} \; | sort | uniq | rg '\.nix$')
numresults=$(echo "$results" | wc -l)
[ "$numresults" -eq 0 ] && echo "$1 not found in ${nixpkgs_toplevel}/pkgs" && exit 1
if [ "$numresults" -gt 1 ]; then
results=$(echo "$results" | awk -F"${nixpkgs_toplevel}/pkgs/" '{print $2}')
file=$(echo "$results" | fzf)
full_path="${nixpkgs_toplevel}/pkgs/$file"
nvim "$full_path"
else
result_path=$(echo "$results" | awk -F"${nixpkgs_toplevel}/pkgs/" '{print $2}')
full_path="${nixpkgs_toplevel}/pkgs/$result_path"
nvim "$full_path"
fi
'';
}