bashfish

How to use bash functions with fish


I have few bash functions like

#!/bin/sh

git-ci() {
    ...
}

When I was not using fish I had a source ~/.my_functions line in my ~/.bash_profile but now it doesn't work.

Can I use my bash functions with fish? Or the only way is to translate them into fish ones and then save them via funcsave xxx?


Solution

  • As @Barmar said fish doesn't care about compatibility because one of its goals is

    Sane Scripting

    fish is fully scriptable, and its syntax is simple, clean, and consistent. You'll never write esac again.

    The fish folks think bash is insane and I personally agree.

    One thing you can do is to have your bash functions in separate files and call them as functions from within fish.

    Example:

    Before

    #!/bin/bash
    
    git-ci() {
        ...
    }
    
    some_other_function() {
        ...
    }
    

    After

    #!/bin/bash
    # file: git-ci
    
    # Content of git-ci function here
    
    #!/bin/bash
    # file: some_other_function
    
    # Content of some_other_function function here
    

    Then put your script files somewhere in your path. Now you can call them from fish.