Skip to content

`hist` command should support snippets #698

Closed
kyrylo opened this Issue Aug 24, 2012 · 4 comments

3 participants

@kyrylo
pry member
kyrylo commented Aug 24, 2012

Recently, for the first time in my life, I used the hist command for the real purpose. And you know what? It sucked. My history is over 48000 entries and I wanted to replay the following: hist -r 48099..48104. Typing big numbers is no fun at all. Also, the code behind these numbers is nothing but a "foobar" class with some special behaviour. But it is very simple and I will undoubtedly need to use it later. The problem is that I relaunch Pry from time to time. In a fresh Pry session I have to press up-arrow key for like 10-20 times before I can find hist -r 48099..48104 command in history.

What if we add --save-snippet (-s) flag, which would save your favourite lines from history and give them a nice name?

No fun.

pry(main)> history --replay 48099..48101

Possible solution.

pry(main)> history --save-snippet 48099..48101 --name foobar-class
pry(main)> history --replay foobar-class

Fun.

% pry
pry(main)> history --replay foobar-class
pry(main)> Foobar.new
# ...

I guess you have a pertinent question: where to store foobar-class? I think we can store snippets in ~/.pry/history_snippets directory.

Example of history snippet file ~/.pry/history_snippets/foobar-class.

# That's all!
history --replay 48099..48101

In contrast to above-said

Maybe we should not touch hist command and add a new command for this kind of things (say, snip and its alias snippet). It would not rely on history.

I would gladly read other opinions (not only from Pry organization members). Would you use that?

@muescha
muescha commented Aug 24, 2012

I think its just an "alias" already implemente in terminal

Maybe we add a "hist --create-alias myname --replay 1234..1236"

@kyrylo
pry member
kyrylo commented Aug 25, 2012

Currently, the implementation is no object. I just showed that in order to explain things more graphically. I'm more interested in the topicality of this idea.

@ghost
ghost commented Aug 25, 2012

I like the general idea although I rarely use the hist command :P

@banister
pry member

i think save-file is a more robust solution than this or perhaps there's room for an alternative solution via a plugin

@banister banister closed this Nov 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.