added stuff
This commit is contained in:
parent
6d31f5b5a1
commit
7d4f626b7d
907 changed files with 70990 additions and 0 deletions
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Function to compile and run a single .cpp file
|
||||
function compile_and_run_file() {
|
||||
filename="$1"
|
||||
basename="''${filename%.*}"
|
||||
|
||||
echo "Compiling $filename..."
|
||||
|
||||
if g++ -o "$basename" "$filename"; then
|
||||
echo "Running $basename..."
|
||||
"./$basename"
|
||||
else
|
||||
echo "Compilation failed."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to prompt user to choose a .cpp file using skim or fzf
|
||||
function choose_cpp_file() {
|
||||
directory="$1"
|
||||
|
||||
if command -v skim >/dev/null 2>&1; then
|
||||
file=$(find "$directory" -maxdepth 1 -type f -name "*.cpp" | skim --ansi --query "")
|
||||
elif command -v fzf >/dev/null 2>&1; then
|
||||
file=$(find "$directory" -maxdepth 1 -type f -name "*.cpp" | fzf)
|
||||
else
|
||||
echo "Error: skim or fzf is required for file selection."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
compile_and_run_file "$file"
|
||||
else
|
||||
echo "No .cpp file selected."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to prompt user to choose a .cpp file recursively using skim or fzf
|
||||
function choose_cpp_file_recursive() {
|
||||
directory="$1"
|
||||
|
||||
if command -v skim >/dev/null 2>&1; then
|
||||
file=$(find "$directory" -type f -name "*.cpp" | sk --ansi --query "")
|
||||
elif command -v fzf >/dev/null 2>&1; then
|
||||
file=$(find "$directory" -type f -name "*.cpp" | fzf)
|
||||
else
|
||||
echo "Error: skim or fzf is required for file selection."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
compile_and_run_file "$file"
|
||||
else
|
||||
echo "No .cpp file selected."
|
||||
fi
|
||||
}
|
||||
|
||||
# Help menu
|
||||
function display_help() {
|
||||
echo "Usage: $0 [options] <file/directory>"
|
||||
echo "Options:"
|
||||
echo " --recursive Look for .cpp files recursively"
|
||||
echo " --help Display this help menu"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " $0 ~/Dev/test.cpp"
|
||||
echo " $0 ~/Dev"
|
||||
echo " $0 ~/Dev --recursive"
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
recursive=false
|
||||
directory=""
|
||||
|
||||
# Check if --help is passed
|
||||
if [[ $1 == "--help" ]]; then
|
||||
display_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--recursive)
|
||||
recursive=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
directory="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if directory is provided
|
||||
if [ -z "$directory" ]; then
|
||||
echo "Error: No directory specified."
|
||||
display_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if directory exists
|
||||
if [ ! -d "$directory" ]; then
|
||||
echo "Error: Directory does not exist."
|
||||
display_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Compile and run or display help menu
|
||||
if [ -f "$directory" ]; then
|
||||
compile_and_run_file "$directory"
|
||||
elif [ "$recursive" = true ]; then
|
||||
choose_cpp_file_recursive "$directory"
|
||||
else
|
||||
choose_cpp_file "$directory"
|
||||
fi
|
94
nyx/homes/notashelf/programs/terminal/shell/bin/default.nix
Normal file
94
nyx/homes/notashelf/programs/terminal/shell/bin/default.nix
Normal file
|
@ -0,0 +1,94 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) getExe;
|
||||
inherit (builtins) readFile;
|
||||
in {
|
||||
home = {
|
||||
# make sure the scripts linked below in the session PATH
|
||||
# so that they can be referred to by name
|
||||
sessionPath = ["${config.home.homeDirectory}/.local/bin"];
|
||||
|
||||
# link scripts to the local PATH
|
||||
file = {
|
||||
".local/bin/preview" = {
|
||||
# Preview script for fzf tab
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "preview";
|
||||
runtimeInputs = with pkgs; [fzf eza catimg];
|
||||
text = readFile ./preview/preview.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/show-zombie-parents" = {
|
||||
# Show zombie processes and their parents
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "show-zombie-parents";
|
||||
runtimeInputs = with pkgs; [fzf eza catimg];
|
||||
text = readFile ./show-zombie-parents/show-zombie-parents.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/tzip" = {
|
||||
# Find all latest .tmod files recursively in current directory and zip them
|
||||
# for tmodloader mods downloaded via steam workshop
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "tzip";
|
||||
runtimeInputs = with pkgs; [zip];
|
||||
text = readFile ./tzip/tzip.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/extract" = {
|
||||
# Extract the compressed file with the correct tool based on the extension
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "extract";
|
||||
runtimeInputs = with pkgs; [zip unzip gnutar p7zip];
|
||||
text = readFile ./extract/extract.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/compilec" = {
|
||||
# Interactively find and compile C++ programs
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "compilec";
|
||||
runtimeInputs = with pkgs; [skim coreutils gcc];
|
||||
text = readFile ./compilec/compilec.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/fs-diff" = {
|
||||
# Show diff of two directories
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "fs-diff";
|
||||
runtimeInputs = with pkgs; [coreutils gnused btrfs-progs];
|
||||
text = readFile ./fs-diff/fs-diff.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/purge-direnv" = {
|
||||
# Purge all direnv links
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "purge-direnv";
|
||||
runtimeInputs = with pkgs; [direnv];
|
||||
text = readFile ./purge-direnv/purge-direnv.sh;
|
||||
});
|
||||
};
|
||||
|
||||
".local/bin/addr" = {
|
||||
# Get external IP address
|
||||
source = getExe (pkgs.writeShellApplication {
|
||||
name = "addr";
|
||||
runtimeInputs = with pkgs; [curl];
|
||||
text = ''
|
||||
#!${pkgs.stdenv.shell}
|
||||
exec curl "$@" icanhazip.com
|
||||
'';
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SAVEIFS=$IFS
|
||||
IFS="$(printf '\n\t')"
|
||||
|
||||
function extract {
|
||||
if [ $# -eq 0 ]; then
|
||||
# display usage if no parameters given
|
||||
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz|.zlib|.cso>"
|
||||
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
|
||||
fi
|
||||
for n in "$@"; do
|
||||
if [ ! -f "$n" ]; then
|
||||
echo "'$n' - file doesn't exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "''${n%,}" in
|
||||
*.cbt | *.tar.bz2 | *.tar.gz | *.tar.xz | *.tbz2 | *.tgz | *.txz | *.tar)
|
||||
tar zxvf "$n"
|
||||
;;
|
||||
*.lzma) unlzma ./"$n" ;;
|
||||
*.bz2) bunzip2 ./"$n" ;;
|
||||
*.cbr | *.rar) unrar x -ad ./"$n" ;;
|
||||
*.gz) gunzip ./"$n" ;;
|
||||
*.cbz | *.epub | *.zip) unzip ./"$n" ;;
|
||||
*.z) uncompress ./"$n" ;;
|
||||
*.7z | *.apk | *.arj | *.cab | *.cb7 | *.chm | *.deb | *.iso | *.lzh | *.msi | *.pkg | *.rpm | *.udf | *.wim | *.xar | *.vhd)
|
||||
7z x ./"$n"
|
||||
;;
|
||||
*.xz) unxz ./"$n" ;;
|
||||
*.exe) cabextract ./"$n" ;;
|
||||
*.cpio) cpio -id <./"$n" ;;
|
||||
*.cba | *.ace) unace x ./"$n" ;;
|
||||
*.zpaq) zpaq x ./"$n" ;;
|
||||
*.arc) arc e ./"$n" ;;
|
||||
*.cso) ciso 0 ./"$n" ./"$n.iso" &&
|
||||
extract "$n.iso" && \rm -f "$n" ;;
|
||||
*.zlib) zlib-flate -uncompress <./"$n" >./"$n.tmp" &&
|
||||
mv ./"$n.tmp" ./"''${n%.*zlib}" && rm -f "$n" ;;
|
||||
*.dmg)
|
||||
hdiutil mount ./"$n" -mountpoint "./$n.mounted"
|
||||
;;
|
||||
*)
|
||||
echo "extract: '$n' - unknown archive method"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
IFS=$SAVEIFS
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
OLD_TRANSID=$(sudo btrfs subvolume find-new /mnt/root-blank 9999999)
|
||||
OLD_TRANSID=${OLD_TRANSID#transid marker was }
|
||||
|
||||
sudo btrfs subvolume find-new "/mnt/root" "$OLD_TRANSID" |
|
||||
sed '$d' |
|
||||
cut -f17- -d' ' |
|
||||
sort |
|
||||
uniq |
|
||||
while read -r path; do
|
||||
path="/$path"
|
||||
if [ -L "$path" ]; then
|
||||
: # The path is a symbolic link, so is probably handled by NixOS already
|
||||
elif [ -d "$path" ]; then
|
||||
: # The path is a directory, ignore
|
||||
else
|
||||
echo "$path"
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
case "$1" in
|
||||
-*) exit 0 ;;
|
||||
esac
|
||||
|
||||
case "$(file --mime-type "$1")" in
|
||||
*text*)
|
||||
bat --color always --plain "$1"
|
||||
;;
|
||||
*image* | *pdf)
|
||||
catimg -w 100 -r 2 "$1"
|
||||
;;
|
||||
*directory*)
|
||||
eza --icons -1 --color=always "$1"
|
||||
;;
|
||||
*)
|
||||
echo "unknown file format"
|
||||
;;
|
||||
esac
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# find all .direnv directories
|
||||
direnv_dirs=$(fd -I -a --hidden --type directory --glob '.direnv')
|
||||
|
||||
# check if any directories were found
|
||||
if [ -z "$direnv_dirs" ]; then
|
||||
echo "No .direnv directories found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# print report
|
||||
echo "The following .direnv directories will be deleted:"
|
||||
echo "$direnv_dirs"
|
||||
|
||||
# confirm deletion
|
||||
read -p "Are you sure you want to delete these directories? (y/n) " -n 1 -r
|
||||
|
||||
# move to a new line
|
||||
echo -en "\n"
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
# Delete directories
|
||||
echo "Deleting directories..."
|
||||
for dir in $direnv_dirs; do
|
||||
rm -rf "$dir"
|
||||
done
|
||||
echo "Directories deleted."
|
||||
else
|
||||
echo "Operation cancelled."
|
||||
fi
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# https://www.linkedin.com/pulse/how-identify-kill-zombiedefunct-processes-linux-without-george-gabra/
|
||||
ps -A -ostat,ppid | grep -e '[zZ]' | awk '{ print $2 }' | uniq | xargs ps -p
|
20
nyx/homes/notashelf/programs/terminal/shell/bin/tzip/tzip.sh
Normal file
20
nyx/homes/notashelf/programs/terminal/shell/bin/tzip/tzip.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
mkdir -p mods/
|
||||
|
||||
# Loop through each subdirectory in the current directory
|
||||
for subdir in */; do
|
||||
# Find the most recently accessed file with a .tmod extension in the subdirectory
|
||||
latest_file=$(find "$subdir" -name "*.tmod" -type f -printf "%T@ %p\n" | sort -n | tail -1 | awk '{print $2}')
|
||||
# Copy the latest file found (if any) to the mods/ directory
|
||||
if [[ -n $latest_file ]]; then
|
||||
cp "$latest_file" "mods/"
|
||||
echo "Copied $latest_file to mods/"
|
||||
else
|
||||
echo "No .tmod files found in $subdir"
|
||||
fi
|
||||
done
|
||||
|
||||
# Zip up the mods/ directory
|
||||
zip -r mods.zip mods/
|
||||
echo -en "Zipped up mods/ directory to mods.zip"
|
Loading…
Add table
Add a link
Reference in a new issue