Comments (9)
Hi, thanks for opening this issue, always good when an open-source project gets its first issue, it means that someone wants to get things done with it.
Regarding your issue, I'm not sure that what you want to do needs path-extractor
:
You can do that exactly with fzf :
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
and then, answer yes for the question "Do you want to add key bindings".
If you restart your shell, you will have keybindings "Ctrl+T" to do exactly the same.
You can then create your own binding that will open vim for a file :
you can look at the keybinding files to see how to do it :
https://github.com/junegunn/fzf/tree/master/shell
Path extractor is a more "dumb" pipe because it will only convert the input into a list of possible paths.
Did that help ?
from path-extractor.
Hi Edi,
Thank for your quickly reply. In my case:
- step 1: I execute a command X, it produces lots of output with many file paths to screen
- step 2: I want to press key binding to capture the list of file path in screen, I do fzf to filter for things I interested in, then press Enter >> to copy it to clipboard (I don't want to open it by editor)
Is there any way to achive this? Thank you very much!
Cheers,
Khon
from path-extractor.
Here is how to do that in bash :
Add this to your bashrc :
bind '"CC": "| pe | uniq | fzf | while read filename; do [ ! -z $filename ] && echo -n $filename | xclip -selection c ; done\n
And then you can do <up>
and press CC, you will have fzf opened to select the filepath. You need to install xclip which is " apt-get install xclip"
from path-extractor.
You could also put !!
At the beginning of the bind, so that you don't even have to press <up>
from path-extractor.
Hi Edi,
Thank for the tip. I highly appreciate that.
If I understand correctly, to press <up>
and press CC is to re-execute the previous command and use CC to activate PE. Right?
But in my case, the command takes long time to go, so it is not convenient to re-execute it again just for copying the path into clipboard. Do you have any suggestion for this case?
Best regards,
Khon
P/S:
- for your suggestion about putting !! at the beginning of the bind, I think it is not flexible, because sometimes I don't really know in advance that I will need to copy the path into clipboard. I want to see the output first, then decide if to copy it later.
- like the tmux-plugins/tmux-fpp (facebook path picker), it scans the output on the screen for path and give you action menu >> I wish path-extractor have such capability, but I need to do fzf filter and copy to clipboard.
from path-extractor.
I guess that you can mix https://github.com/tmux-plugins/tmux-fpp/blob/master/fpp.tmux and replace fpp by the snippet I put before. I will be integrating this my self tomorrow, and will be posting the full code snippet if you haven't already find out
from path-extractor.
Create a file in ~/scripts/tmux-path-extractor.sh
#!/usr/bin/env bash
copy () {
input=$1
if [ ! -t 0 ]; then
[ "$input" ] || input=$(cat)
fi
echo -e -n "$input" > ~/.clipboard
which xclip 2>/dev/null && echo -e -n "$input" | xclip -selection c && exit 0
tmux set-buffer "$(echo -e -n $input)"
}
fzf_with_opts="fzf +s --tac +m --tiebreak=index --toggle-sort=ctrl-r"
get_input="cat /tmp/tmux-buffer | grep '.' | grep -v ' \\$ ' | grep -v ' \\\$\$'"
tmux bind-key "f" capture-pane \\\; \
save-buffer /tmp/tmux-buffer \\\; \
new-window -c "#{pane_current_path}" "sh -c \"$get_input | pe | uniq | $fzf_with_opts | copy && rm /tmp/tmux-buffer\""
and add
run-shell ~/scripts/tmux-path-extractor.sh
at the end of your tmux.conf
If you press f, you will get to choose your filepath.
Did that work for you ?
from path-extractor.
Hi Edi,
Thank you very much! You are so kind.
I did try your script but it didn't work. When I press "f" in tmux, it successfully copied tmux buffer into /tmp/tmux-buffer and pipe into pe and fzf, but the copy() was not visible (I tested it by add "touch abc.txt" inside copy() function).
However, your script is still useful to me. I create an alias and
alias pp="tmux capture-pane && tmux save-buffer /tmp/tmux-buffer && cat /tmp/tmux-buffer | grep '.' | grep -v ' \\$ ' | grep -v ' \\\$\$' | pe | uniq | fzf | xargs echo -n | xclip -i -sel p -f | xclip -i -sel c"
And bind key to that alias in bash, and now it works well for me 💃
bind '"PP": "pp\C-m'
Thank you very much! Have a nice weekend.
Cheers,
Khon
P/S: you can create tmux plugin for path-extractor, I think it is useful. :D
from path-extractor.
I don't exactly see the point of creating a tmux plugin for this. Shouldn't I just put your script into the readme, so that others can use it ? I find it much simpler to have just those two lines, so that you can edit them the way you want if you need it
from path-extractor.
Related Issues (9)
- Installation fails on Go 1.18 HOT 1
- Is it possible to have an absolute path after the process of path-extractor? HOT 2
- Distribute on OS X homebrew HOT 5
- Possible to handle paths with spaces? HOT 2
- Is it expected that it doesn't recognize paths without / or .? HOT 2
- [enhancement] add one option -s and -u to sort or uniq the path HOT 2
- missing license for the repo HOT 1
- Filenames with diacritics HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from path-extractor.