Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use bash functions with fish

Tags:

bash

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?

like image 823
ivkremer Avatar asked Oct 17 '25 19:10

ivkremer


1 Answers

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.

like image 141
Adham Zahran Avatar answered Oct 19 '25 08:10

Adham Zahran