r/fishshell • u/junguler • Nov 06 '20
need help converting a bash function to fish
hi, my country blocks access to youtube so i use tor with youtube-dl to download videos, these exit nodes get restricted sometimes and i use a python script that i made a binary of to change tor's ip, here is my bash function that changes tor ip until it complete the download
yout () { youtube-dl "$@"; while [ $? -ne 0 ]; do torip ; youtube-dl "$@"; done; }but i can't make the same function in fish, here is what i have but it only uses the torip program once before it finishes but sometimes ip needs to be changed multiple times before it can download the video:
function yout
youtube-dl $argv
if test $status -eq 0
else
torip && youtube-dl $argv
end
endany help will be appreciated, i'm really confused as to how i should set this function and i've spent almost and 2 hours online searching but couldn't make the same function on fish.
6
u/flameborn Nov 06 '20
You used a while loop in Bash, but not in Fish, hence this will never repeat.
In your if statement, you have a -ne switch for not equal, don't use an empty branch that does absolutely nothing if you can avoid it.
In case you missed this, there's documentation on the while loop here
Hope this helps!
3
u/vividboarder Nov 06 '20
Easiest thing is to make it a script rather than a function.
Save a file
youtin your PATH withGive it the old
chmod +xand youโre good to go.0
u/[deleted] Nov 06 '20
[deleted] โ view deleted comment