Bash to Fish Conversion: Display custom message when CD’ing into a specific directory Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Bash to Fish Conversion: Display custom message when CD’ing into a specific directory without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Basically, I’d like to create a file .cd-reminder with an announcement/message inside a specific directory. It will be displayed every time someone ‘cd’ into that specific directory.

There is a shell script for that already and I’m currently using Fish and not familiar on how to convert it; any help appreciated!

reminder_cd() { 
    builtin cd "$@" && { [ ! -f .cd-reminder ] || cat .cd-reminder 1>&2; }
}

alias cd=reminder_cd`

Answer

function cd
    builtin cd $argv
    and test -f .cd-reminder
    and cat .cd-reminder
end

I just realized this will return a non-success exit status when the .cd-reminder file does not exist in a directory. use this instead so the function will only return non-success if you can’t cd to the given dir.

function cd
    builtin cd $argv
    and begin
        test -f .cd-reminder
        and cat .cd-reminder
        or true
    end
end
We are here to answer your question about Bash to Fish Conversion: Display custom message when CD’ing into a specific directory - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji