dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.
MIT License
36.49k stars 3.28k forks source link

Simplifying the cycle function for toggling #116

Open justinyaodu opened 3 years ago

justinyaodu commented 3 years ago

I believe the cycle function can be simplified when there are only two elements to toggle between:

arr=(true false)

toggle() {
    printf '%s ' "${arr[${i:=0}]}"
    ((i=1-i)) # ((i=i^1)) also works
}

What do you think?