rickyrockrat / parcellite

GNU General Public License v3.0
220 stars 29 forks source link

Is there a way to save the history to a file from the commandline? (ie, run the same function as in `icon-right-click > save as`) #54

Closed OwenAR closed 3 years ago

OwenAR commented 3 years ago

Is there a way to save the history to a file from the commandline? (ie, run the same function as in icon-right-click > save as)

-h only tells me about:

Application Options:
  -n, --no-icon       Do not use status icon (Ctrl-Alt-P for menu)
  -c, --clipboard     Print clipboard contents
  -p, --primary       Print primary contents
  -v, --version       Display Version info

and the manpage only gives a few examples of adding items to the clipboard.

(EDIT: ... sorry if this is some dumb mistake on my side like a broken version or something. (Parcellite 1.2.1, GTK 2.24.32))

jbriales commented 3 years ago

I was precisely looking for this same feature.

I've been familiarizing myself with the source code and it seems like it should be doable, but before digging deeper, I'd rather ask about the authors opininion :)

Concretely the code in main is not trivial and I wonder where the piece of code calling save_history_as_text should be best placed.

rickyrockrat commented 3 years ago

I do have a fifo command interface that was started for things like this, but the last user's interest faded, and nothing interesting happened with it.

In other words, you want a way somehow to not use the GUI to save history as text? A parcellite -o fname.txt while a current instance is running?

OwenAR commented 3 years ago

@rickyrockrat yeah, that sounds like exactly what I was expecting to find (something like parcellite -o fname.txt)

Don't you occasionally want to pop open the clipboard history to work with it in a buffer in your editor (emacs/sublime/whatever)?

eg if you go like "oh, I copy-pasted a bunch of links about an hour ago, and I need (some) of them..." so you'd pop open a dump of the clipboard history, select the range you want, then select all the lines in that with "http" or whatever, (then filter/format them however), etc...

Or say you want to grab the last X things you pasted (maybe with one or two manual exceptions/special-cases) and grab them as into single lines in a buffer, so you can sort/reverse/unique/format them or whatever...

Ya know?

Do you have some other way of accomplishing that kind of thing, or...?

(I use a lot of multi-selection editing, regex-select/modify, elastic tabstops, etc, so... it's a hammer that makes a lot of things look like very convenient nails.)

rickyrockrat commented 3 years ago

OK, so I dug into one of the things I was developing, and I can implement this very easily:

echo "save_history file=/path/to/file" > ~/.local/share/parcellite/fifo_cmd

Would that work for you?

rickyrockrat commented 3 years ago

I probably could cause parcellite itself to do that -o thing as well. And no, I don't have your use case. I just use the hot-key history, select, then paste.

rickyrockrat commented 3 years ago

Wow. that was far easier than I thought. I remembered adding that hook. Anyhow, I have a working bit that works like this: echo "save_history /tmp/hist.txt" >fifo_cmd

And it dumps the history into /tmp/hist.txt. I just noticed a feature that someone asked for that prepends line info to each entry. Might have to have a mode that doesn't do that.

rickyrockrat commented 3 years ago

Well, this turned into a new feature, and dialog option. Here's what is working: echo "save_history /tmp/hist.txt" >fifo_cmd - straight history text echo "save_historyN /tmp/hist.txt" >fifo_cmd - history text with line numbers.

Now I want to add a range of line numbers, and of course persistent or normal history, because I can. Ugh.

rickyrockrat commented 3 years ago

OK, check out commit 6410b4e

OwenAR commented 3 years ago

Oh wow, fast! Thanks a bunch! :)