what a struggle..

This commit is contained in:
Lord Of Nougate 2022-02-04 22:44:24 +01:00
parent 9d4db53aac
commit 72c9f2cace
2 changed files with 24 additions and 18 deletions

24
eachf Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/python
import sys, os
if sys.argv[1] in ["--help", "-h"]:
print("\nWelcome to the cli helper for foreach loops.")
print("\nUsage:\neachf [path] [filter] [command1] [command2]")
print("\nDescription:\nIn between the two command-arguments, the filename will be inserted.\n")
exit()
files = os.listdir(sys.argv[1])
filtered_files = []
commands = []
for file in files:
if sys.argv[2] in file:
filtered_files.append(file)
for f in filtered_files:
c = sys.argv[3] + " " + f + " " + sys.argv[4]
commands.append(c)
for command in commands:
os.system(command)

18
foreach
View File

@ -1,18 +0,0 @@
#/bin/bash
if [[ "$1" == "--help" ]]
then
echo -e "\nforeach [filter] [path] [action]\n"
exit
elif [[ "$1" == "-h" ]]
then
echo -e "\nforeach [filter] [path] [action]\n"
exit
fi
action=$3
filter=$1
path=$2
for f in $path/$filter
do
$action
done