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: Option to run fd in different directory than pwd #475

Closed
hajdamak opened this issue Sep 12, 2019 · 9 comments
Closed

Feature request: Option to run fd in different directory than pwd #475

hajdamak opened this issue Sep 12, 2019 · 9 comments

Comments

@hajdamak
Copy link
Contributor

Git like -C option would be handy to run fd as if it was started in specified path rather than the current working directory.

@hajdamak hajdamak changed the title Feature request: Option to run fd in different directory that pwd Feature request: Option to run fd in different directory than pwd Sep 12, 2019
@sharkdp
Copy link
Owner

sharkdp commented Sep 13, 2019

Thank you for the feedback.

What is the use case for this?

Have you considered alternative options?

  • fd … some/other/directory. This is not quite the same, as the paths will be prefixed with some/other/directory, but it's close. If you are interested in absolute paths (-a/--absolute-path), the result would be the same as with a -C option.
  • Use a subshell (cd some/other/directory; fd …)

@sharkdp
Copy link
Owner

sharkdp commented Sep 15, 2019

We're most probably not going to implement this in fd.

@sharkdp sharkdp closed this as completed Sep 15, 2019
@hajdamak
Copy link
Contributor Author

hajdamak commented Sep 16, 2019

I am using fd output to feed skim on large directories. I need this to be as instant as possible. Having base directory in all entries makes fuzzy search a lot less efficient.

I am using this in Fish script which does not support subshell and using cd or pushd/popd messes up Fish history which makes back/forward keyboard shortcuts less efficient.

I have tried to pipe fd output to sed/sd before feeding skim in order to remove base directory from the list but this gets quite slow.

@sharkdp
Copy link
Owner

sharkdp commented Sep 16, 2019

Ok, but a simple wrapper script would work, right?

Something like

run-fd-in.sh

#!/bin/bash

set -e

base_directory="$1"
shift

cd "$base_directory"
fd "$@"

which can be used like

./run-fd-in.sh <base-directory> [fd-options…]

@hajdamak
Copy link
Contributor Author

Yeah, that should work. I hoped to avoid spawning another shell though.
Just wondering, are there any other arguments against this functionality besides KISS, which I totally understand.

@sharkdp
Copy link
Owner

sharkdp commented Sep 17, 2019

Just wondering, are there any other arguments against this functionality besides KISS, which I totally understand.

No, I'm just trying to keep fd simple (see beginning of README).

There is one compromise which I would be willing to make because this should actually be really simple to implement: we add a new "long" command-line option (not -C, but maybe --base-directory) as a hidden option that would not show up in the -h help text (and maybe not even in the --help text). If those are just a few lines of code along the lines of if (base-directory option is present) { set_current_working_directory(…); }, I'd be willing to include this in fd.

@hajdamak
Copy link
Contributor Author

Pull request #509 created.

@sharkdp
Copy link
Owner

sharkdp commented Dec 23, 2019

closed via #509

@sharkdp sharkdp closed this as completed Dec 23, 2019
@sharkdp
Copy link
Owner

sharkdp commented Mar 22, 2020

Released in fd 7.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants