Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Normally to overwrite a function you can use builtin or a path to a binary.

But specifically when I'm overwriting cd it's a bit clunky:

source /opt/homebrew/share/fish/functions/cd.fish
functions -e _cd_orig
functions -c cd _cd_orig

function cd -d "quickly cd and ls" -w cd
    if test (count $argv) -eq 1
        if test ! -e $argv[1] -a "$argv[1]" != -
            new -d $argv[1]
        end
    end
    _cd_orig $argv
    ls-preview
end

Is there an easier way to do this?

You must be logged in to vote

Replies: 2 comments

Comment options

There's not an easier way when you want to keep the old function around instead of replace it, no.

You could test if _cd_orig and cd exist before sourcing and renaming:

if not functions -q _cd_orig
    if not functions -q cd
        source /opt/homebrew/share/fish/functions.cd.fish
    end
    functions -c cd _cd_orig
end

Though it's not a big deal, unless you are sourcing the file this belongs in often.

You must be logged in to vote
0 replies

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.