This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / name-generator / flake-module.nix
1.7 kB 57 lines
1{ ... }: 2{ 3 perSystem = 4 { pkgs, ... }: 5 let 6 dataFiles = pkgs.stdenv.mkDerivation { 7 name = "name-generator-data"; 8 src = ./.; 9 installPhase = '' 10 mkdir -p $out 11 cp adjectives.txt nouns.txt $out/ 12 ''; 13 }; 14 in 15 { 16 packages.name-generator = pkgs.writeShellApplication { 17 name = "name-generator"; 18 runtimeInputs = [ pkgs.bash ]; 19 text = '' 20 # Data files location 21 DATA_DIR="${dataFiles}" 22 # Default separator 23 SEPARATOR="-" 24 # Parse command line options 25 while [[ $# -gt 0 ]]; do 26 case $1 in 27 -s|--separator) 28 SEPARATOR="$2" 29 shift 2 30 ;; 31 -h|--help) 32 echo "Usage: $0 [OPTIONS]" 33 echo "Generate a random name in the format: adjective-noun" 34 echo "" 35 echo "Options:" 36 echo " -s, --separator CHAR Use CHAR as separator (default: -)" 37 echo " -h, --help Show this help message" 38 exit 0 39 ;; 40 *) 41 echo "Unknown option: $1" 42 exit 1 43 ;; 44 esac 45 done 46 # Read adjectives and nouns 47 mapfile -t ADJECTIVES < "$DATA_DIR/adjectives.txt" 48 mapfile -t NOUNS < "$DATA_DIR/nouns.txt" 49 # Select random adjective and noun 50 ADJ_INDEX=$((RANDOM % ''${#ADJECTIVES[@]})) 51 NOUN_INDEX=$((RANDOM % ''${#NOUNS[@]})) 52 # Output the generated name 53 echo "''${ADJECTIVES[$ADJ_INDEX]}''${SEPARATOR}''${NOUNS[$NOUN_INDEX]}" 54 ''; 55 }; 56 }; 57}