-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
_: '' | ||
# Function to compile and run a single .cpp file | ||
function compile_and_run_file() { | ||
filename="$1" | ||
basename="''${filename%.*}" | ||
echo "Compiling $filename..." | ||
g++ -o "$basename" "$filename" | ||
if [ $? -eq 0 ]; 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 | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
lib, | ||
pkgs, | ||
... | ||
}: '' | ||
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'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
lib, | ||
pkgs, | ||
... | ||
}: '' | ||
#> Syntax: bash | ||
# Copied from Elkowar | ||
case "$1" in | ||
-*) exit 0;; | ||
esac | ||
case "$(${lib.getExe pkgs.file} --mime-type "$1")" in | ||
*text*) | ||
${lib.getExe pkgs.bat} --color always --plain "$1" | ||
;; | ||
*image* | *pdf) | ||
${lib.getExe pkgs.catimg} -w 100 -r 2 "$1" | ||
;; | ||
*directory*) | ||
${lib.getExe pkgs.eza} --icons -1 --color=always "$1" | ||
;; | ||
*) | ||
echo "unknown file format" | ||
;; | ||
esac | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
lib, | ||
pkgs, | ||
... | ||
}: '' | ||
#> Syntax: bash | ||
# Send to host | ||
[ -f "$1" ] && op="cat" | ||
''${op:-echo} "''${@:-$(cat -)}" \ | ||
| ${lib.getExe pkgs.curl} -sF file='@-' 'http://0x0.st' \ | ||
| tee /dev/stderr \ | ||
| tr -d '\n' \ | ||
| ${pkgs.wl-clipboard}/bin/wl-copy -n | ||
'' |