bashrc: new repeat and parallel

This commit is contained in:
2024-09-23 07:55:44 +00:00
parent 200d4463d7
commit 94f65ed268

View File

@@ -123,6 +123,45 @@ add() {
fi
diff
}
parallel() {
if [ $# -lt 2 ]; then
echo "Usage: parallel <number_of_instances> <command>"
return 1
fi
count=$1
shift
command="$@"
for i in $(seq 1 $count); do
eval "$command" &
done
wait
}
repeat() {
if [ $# -lt 2 ]; then
echo "Usage: repeat <interval>[s|m|h] <command>"
return 1
fi
interval=$(echo $1 | sed 's/[smh]$//')
unit=${1##*[0-9]}
command="${@:2}"
case $unit in
s|'') seconds=$interval;;
m) seconds=$((interval * 60));;
h) seconds=$((interval * 3600));;
*) echo "Invalid time unit. Use 's' for seconds, 'm' for minutes, 'h' for hours, or no unit for seconds."; return 1;;
esac
while true; do
eval $command
sleep $seconds
done
}
alias remote="git remote -v"
alias stash="git stash"
alias branch="git branch"