I am not a coder or a programmer, I just try to learn but I have some limitations...
I'd like to mount a webdav resource when I logging into the session (virtual console), however I'd like to check if the folder is empty to determine if the resource must be mounted or not.
This is the script that I tried to figure out:
if status is-interactive # Commands to run in interactive sessions can go here # # # Start WebDav # # check if the folder is empty function tst command find /mnt/drive -maxdepth 0 -empty end # Compare the variable and mount the resource function drive set mnt '/mnt/drive' if test (tst) = $mnt command rclone mount drive:/ /mnt/drive/ --vfs-cache-mode writes --daemon else # Actually I would use a "do nothing" echo "Resource already mounted" end end drive & # end WebDav end
Unfortunately it doesn't work, the login session get stuck hence I have to open another virtual console getting this error:
= /mnt/drive ^ ~/.config/fish/config.fish (line 12): if test (tst) = $mnt ^ in function 'drive' called on line 19 of file ~/.config/fish/config.fish from sourcing file ~/.config/fish/config.fish called during startup Resource already mounted
I don't understand what I am doing wrong... 😩
Now it works thanks!!!
if status is-interactive # Commands to run in interactive sessions can go here # # Start WebDav function drive set tst (find /mnt/drive -maxdepth 0 -empty) set mnt '/mnt/drive' if test "$tst" = "$mnt" command rclone mount drive:/ /mnt/drive/ --vfs-cache-mode writes --daemon & else true end end drive & # end WebDav end