From b09a2d561277de3e6f4d97c148d99a41aa395909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Krop=C3=A1=C4=8Dek?= Date: Tue, 8 Jul 2025 01:05:31 +0200 Subject: [PATCH] added helper script --- flake.nix | 1 + homeManagerModules/packages/development.nix | 1 + overlays/default.nix | 1 + packages/whst/default.nix | 67 +++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 packages/whst/default.nix diff --git a/flake.nix b/flake.nix index e2c534a..8713662 100644 --- a/flake.nix +++ b/flake.nix @@ -82,6 +82,7 @@ uv-bin = pkgs.callPackage ./packages/uv { }; lanshare = pkgs.callPackage ./packages/lanshare { }; warpssh = pkgs.callPackage ./packages/warpssh { }; + whst = pkgs.callPackage ./packages/whst { }; }; formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style; hydraJobs = { diff --git a/homeManagerModules/packages/development.nix b/homeManagerModules/packages/development.nix index e05101e..c8d1e06 100644 --- a/homeManagerModules/packages/development.nix +++ b/homeManagerModules/packages/development.nix @@ -33,6 +33,7 @@ in rpi-imager wireguard-tools warpssh + whst ]; programs.go = { enable = true; diff --git a/overlays/default.nix b/overlays/default.nix index 028361f..edc732e 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -8,6 +8,7 @@ in uv-bin = self.packages.x86_64-linux.uv-bin; lanshare = self.packages.x86_64-linux.lanshare; warpssh = self.packages.x86_64-linux.warpssh; + whst = self.packages.x86_64-linux.whst; kropcloud-utils = inputs.kropcloud-utils.packages.x86_64-linux.default; gamescope = prev.gamescope.overrideAttrs (oldAttrs: { patches = (oldAttrs.patches or [ ]) ++ [ diff --git a/packages/whst/default.nix b/packages/whst/default.nix new file mode 100644 index 0000000..4d8a1dc --- /dev/null +++ b/packages/whst/default.nix @@ -0,0 +1,67 @@ +{ + writeShellScriptBin, +}: +writeShellScriptBin "whst" '' + print_help () { + cat << EOF + Usage: whst [options] + + Check the meaning or details of a given HTTP status code. + + Arguments: + status_code Integer HTTP status code to look up (e.g., 200, 404). + + Options: + -h Show this help message and exit. + + Examples: + whst 200 + whst 404 -h + + EOF + } + + OPTSTRING="h" + + while getopts "$OPTSTRING" opt; do + case "$opt" in + h) + print_help + exit 0 + ;; + ?) + echo "Invalid option: -$OPTARG." >&2 + exit 1 + ;; + esac + done + + shift $((OPTIND - 1)) + + if (( $# < 1 )); then + echo "Error: Missing required status_code argument." >&2 + echo "Use -h for help." >&2 + exit 1 + fi + + status_code="$1" + + if ! [[ "$status_code" =~ ^[0-9]+$ ]]; then + echo "Error: status_code must be an integer." >&2 + exit 1 + fi + + url="https://http.cat/$status_code" + + xdg-open "$url" >/dev/null 2>&1 + + ret=$? + + if (( ret != 0 )); then + echo "Failed to open browser automatically. Here's the URL instead:" + echo "$url" + exit 1 + fi + + exit 0 +''