Giter Site home page Giter Site logo

Comments (4)

faho avatar faho commented on May 25, 2024

function --inherit-variable file, see the docs.

Have you tried just adding this directory to $PATH instead? (I would then also recommend not using the fish function directory for this)

from fish-shell.

p7r0x7 avatar p7r0x7 commented on May 25, 2024

I wanted to use POSIX shell scripts for all of my personal scripts (that I'd previously held in the functions folder) without .sh being part of the name (though I realize that extension is not strictly necessary).

I know this isn't a usual choice, but I'm in an unusual position of wanting to continue using fish as my daily interactive shell and switch to POSIX scripts for everything (because I've had a much better time of it than with fish scripts).

from fish-shell.

faho avatar faho commented on May 25, 2024

I think you were anticipating a response I didn't give.

Let me try to expand on my answer.

Your immediate problem here is that you need to include $file now, when the function is defined. $argv will be filled in when you call it, but when you call it the value of $file will no longer exist (and even if it does, $file was a local variable and so the function would not have access to it anyway).

That's what --inherit-variable does - function $funcname --inherit-variable file will add a snapshot of $file to the function when it is defined.


This would generally work, but this dance is also just kind of pointless.

The way of least resistance is to just move your scripts to a directory, call them whatever you want, make them executable, add a shebang and then add that directory to $PATH.

E.g. move them to ~/bin and run fish_add_path ~/bin (once interactively is usually enough). And then simply don't define these as functions at all.

Importantly, these approaches will both share a rather big limitation: These run in dash (or bash, or whatever), and so any changes they make to the environment won't take inside fish.

When you change a variable or cd in a script like this, that affects the process running it, which won't be fish.

But making them a function doesn't magically change that.

from fish-shell.

p7r0x7 avatar p7r0x7 commented on May 25, 2024

Yeah, I was hoping for the second half that; you'd said enough to get across the first part. And yes, I am aware environment things won't affect fish (and I was going to account for that if necessary, but really I usually don't want them to). I was hoping for your response based on why I said I was doing this in case you had insight for me, so thank you.

After thinking on it, I'm probably going to go with my original idea so I can keep my .sh and .fish scripts together (the shell prompt really should be fish).

from fish-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.