bashrc: new repeat and parallel
This commit is contained in:
@@ -123,6 +123,45 @@ add() {
|
|||||||
fi
|
fi
|
||||||
diff
|
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 remote="git remote -v"
|
||||||
alias stash="git stash"
|
alias stash="git stash"
|
||||||
alias branch="git branch"
|
alias branch="git branch"
|
||||||
|
|||||||
Reference in New Issue
Block a user