Search code examples
terminalfishdetach

How do I get fish to swallow? or at least to detach itself from a program


I want to be able to type "vlc Music/" and then have the terminal go away until i close the newly launched VLC window. I've looked in the documentation and elsewhere and couldn't find a solution. I'd be fine with the terminal staying open if I can still use it, I just don't want to have a useless window open, and using an abbreviation to launch a music player is much more preferential to using VLC's GUI after launching it with Rofi.

Plus, if I learn how to do this, I can do the same thing for all my programs and be able to just use the terminal to launch my applications instead of needing to use Rofi all the time.


Solution

  • Assuming you don't care about whatever vlc outputs:

    function vlc --wraps=vlc
        command vlc $argv >/dev/null 2>&1 &
        disown
    end
    funcsave vlc
    

    That will launch vlc into the background, discarding any stdout or stderr, and then detach the process from the terminal.

    If this is something you're going to do repeatedly, you can do somethinig like this:

    function disowner -a cmd
        eval "function $cmd --wraps=$cmd
            command $cmd \$argv >/dev/null 2>&1 &
            disown
        end"
    end
    
    disowner vlc
    funcsave vlc