Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: current script directory #1818

Closed
wieczorek1990 opened this issue Nov 19, 2014 · 7 comments
Closed

Feature request: current script directory #1818

wieczorek1990 opened this issue Nov 19, 2014 · 7 comments

Comments

@wieczorek1990
Copy link

Hi,
I would like not to have to type this code in almost every script I write:

set script (status -f)
set dir (dirname $script)

Please provide a status -d command which will return $dir

@ridiculousfish ridiculousfish added this to the fish-future milestone Nov 20, 2014
@ridiculousfish
Copy link
Member

You can do a little better with set dir (dirname (status -f))

@zanchey
Copy link
Member

zanchey commented Nov 21, 2014

For my own education, what do you use that variable for? It's not something that's come up in many years of systems admin and I'm wondering if I'm missing a trick!

@terlar
Copy link
Contributor

terlar commented Nov 21, 2014

I am using that and it would be for sourcing other files in relation to the current file. Either just like that directly or if you source several other files from the file you source.

Example:

➥ tree
├── files
│   ├── file_a.fish
│   └── file_b.fish
└── root_file.fish

root_file.fish

echo root_file
source files/file_a.fish

file_a.fish

echo file_a
source (dirname (status -f))/file_b.fish

file_b.fish

echo file_b

Because source cannot be used reliably because it would depend on the location you execute the script. I basically never use source without (dirname (status -f)).

@zanchey
Copy link
Member

zanchey commented Nov 21, 2014

Cool.

@wieczorek1990
Copy link
Author

If you know that certain files are in a directory relative to the script
directory then it's nice to state that other directory using the directory
the script is in. E.g. you have a scripts directory in the root of the
project and some files that need to be compiled (e.g. CoffeeScript to
JavaScript or some Handlebars templates) under src directory. You get the
root directory by obtaining the directory the script is in and by appending
"/..". You change the directory to project root and do easily what you want.

pt., 21 lis 2014, 14:09 Terje Larsen użytkownik notifications@github.com
napisał:

I am using that and it would be for sourcing other files in relation to
the current file. Either just like that directly or if you source several
other files from the file you source.

Example:

➥ tree
├── files
│ ├── file_a.fish
│ └── file_b.fish
└── root_file.fish

root_file.fish

echo root_file
source files/file_a.fish

file_a.fish

echo file_a
source (dirname (status -f))/file_b.fish

file_b.fish

echo file_b
source (dirname (status -f))/file_b.fish


Reply to this email directly or view it on GitHub
#1818 (comment)
.

@terlar
Copy link
Contributor

terlar commented Dec 19, 2014

For the sourcing it might make sense with something like source_relative also. But that would be kind of weird when you are not inside a script.

@faho
Copy link
Member

faho commented Sep 26, 2020

Fish 3.2 now allows status dirname and status basename as shortcuts.

I don't think there's anything left to do here.

@faho faho closed this as completed Sep 26, 2020
@faho faho modified the milestones: fish-future, fish 3.2.0 Sep 26, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants