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

Print selected path to stdout #25

Closed
wookayin opened this issue Feb 7, 2019 · 6 comments
Closed

Print selected path to stdout #25

wookayin opened this issue Feb 7, 2019 · 6 comments
Assignees

Comments

@wookayin
Copy link

wookayin commented Feb 7, 2019

In order to use broot as a CLI tool (the Unix philosophy!), we would need an option to make broot print the selected path into stdout, rather than simply opening it as a Desktop application. (I think it should be a default behavior)

Please see fzf for an example.

@Canop
Copy link
Owner

Canop commented Feb 7, 2019

There are already discussions around this problem which isn't as easy as it seems, hence the shell function (which could be extended to other use cases than just cd).

See for example https://gitlab.redox-os.org/redox-os/termion/issues/163 for more insight on the problem

Note that there's a command, :print_path, which outputs the selected path.

@wookayin
Copy link
Author

wookayin commented Feb 7, 2019

Thanks for your follow-up. So that's why broot has --out option but not stdout.

@Canop
Copy link
Owner

Canop commented Jun 11, 2019

It's no more a termion problem but a crossterm one (I dropped termion and now use crossterm in order to allow windows compatibility).
There will be several things to fix in crossterm. First issue: crossterm-rs/crossterm#150

@Canop Canop self-assigned this Jun 11, 2019
@Canop Canop closed this as completed in 803a8d2 Nov 3, 2019
@sgraf812
Copy link

It's still unclear to me how to support file selection via --out or stdout. To clarify what I think this issue is about:

  1. Launch broot ... $outfile ... (this could be done from within e.g. vim, which creates a temporary $outfile for communication)
  2. Find the desired file you want to open, e.g. a/b/foo.txt, by typing afoo.tx
  3. Press <enter> (this is important for ergonomics in that particular use case, :pp is out of the question)
  4. broot exits and has written the file name to $outfile

I don't care whether $outfile is written as a stdout redirect or via --out or some such. All I want is the behavior of ranger --choose-files=$outfile, which lacks easy fuzzy find support without elaborate plugins. I'm currently evaluating if it's easier to augment ranger than it is to bend broot.

Note also that ideally I wouldn't have to pollute my config file (the location of which I apparently can't overwrite), because then I wouldn't be able to use <enter> to focus a sub-dir in regular shell mode br.

@Canop
Copy link
Owner

Canop commented Dec 27, 2020

If I follow you, what you want is solved with the following scenario:

  1. create a file ~/.config/select.toml with this content:
[[verbs]]
invocation = "ok"
key = "enter"
leave_broot = true
execution = ":print_path"
apply_to = "file"
  1. create a shortcut of some type, for example using ~/.bash_aliases
alias bo="br --conf ~/.config/broot/select.toml"
  1. you can then use broot as a selector in other commands:
echo $(bo)

or

echo $(bo some/path)

In this scenario the configuration file was used to ensure you can select a file with the enter key. In similar scenarios I specify colors to remember me I'm not in a standard broot. See Use broot and meld to diff before commit.

Please tell me how I answered your question. If it's positive, I may add this as a "trick" in the documentation.

@sgraf812
Copy link

Yes, your use case should be equivalent.

Ahh, yes, --conf was basically one solution I was hoping for, but I couldn't find it in man broot.

I just tried it out in my workflow and it works perfectly. Thank you! :)

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

3 participants