EmilyDirsh / hotwire-shell

Automatically exported from code.google.com/p/hotwire-shell
Other
0 stars 0 forks source link

Import bash history #141

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be cool if hotwire read my mind retroactively, else, it could just
import my current bash history :-)

I've done a quick patch to implement it, but it has several problems:

1. I carry a 50000 line bash history (most of my commands are a ctrl+r away
:-) and doing the import takes some minutes.

2. Even using the async thread the UI blocks a lot when trying to complete
while it is importing which I think is due to the the DB file contention.

3. There are probably better default values to pass as lang_uuid and cwd.

Please review.

Original issue reported on code.google.com by TiagoMa...@gmail.com on 1 Feb 2008 at 3:34

Attachments:

GoogleCodeExporter commented 9 years ago
+        try:
+            os.stat(path)
+            self.__have_history = True
+        except:
+            self.__have_history = False

I'd just say:

have_history = os.path.exists(path)

+            lines = f.readlines()
+            for line in lines:
+                line = line[:len(line)-1] # strip the newline

That's going to read all 50000 lines into memory at once, and needlessly 
computes
len().  This is cleaner:

for line in f:
    line = line.strip()
    self.__do_append_command(conn, "62270c40-a94a-44dd-aaa0-689f882acf34", line, "/")

> 3. There are probably better default values to pass as lang_uuid and cwd.

Yeah - we probably want to use the UnixShellLanguage uuid I think, right?  It's 
a bit
of a tough call because a lot of those commands are valid HotwirePipe too, but 
we
might as well err on the side of compatibility.

> 2. Even using the async thread the UI blocks a lot when trying to complete
while it is importing which I think is due to the the DB file contention.

Hm.  One thing that jumps out at me is that we're doing a transaction per line, 
which
is going to be very expensive.  We should do it all in one transaction; I'd 
just copy
the SQL code out of __do_append_command, and wrap the whole 
__import_bash_history in
cursor.execute("BEGIN") ... cursor.execute("COMMIT").

Original comment by cgwalt...@gmail.com on 1 Feb 2008 at 4:29

GoogleCodeExporter commented 9 years ago
Though, if we do use the UnixShell language, then it won't currently show up in 
the
HotwirePipe history search.  But maybe we should make the history search all
languages, not just the current one? 

Original comment by cgwalt...@gmail.com on 1 Feb 2008 at 4:45

GoogleCodeExporter commented 9 years ago
> have_history = os.path.exists(path)

Done. Python is even less verbose than my thinking :-)

> That's going to read all 50000 lines into memory at once, and needlessly 
computes
> len().  This is cleaner:

Done.

> Hm.  One thing that jumps out at me is that we're doing a transaction per 
line,
which is going to be very expensive.  We should do it all in one transaction; 
I'd
just copy the SQL code out of __do_append_command, and wrap the whole
__import_bash_history in cursor.execute("BEGIN") ... cursor.execute("COMMIT").

Done, now I can't even notice it!

> Though, if we do use the UnixShell language, then it won't currently show up 
in the
HotwirePipe history search.  But maybe we should make the history search all
languages, not just the current one? 

I think the history should search all languages. Since the language is kept for 
each
command anyway it's a matter of changing to the language specified on a given 
history
entry.

Original comment by TiagoMa...@gmail.com on 1 Feb 2008 at 12:54

Attachments:

GoogleCodeExporter commented 9 years ago
Looks good, thank you for the patch!

Committed r953
    M   hotwire/state.py
r953 = 41bb0b874095678a1eb06eed907188756a8ef668 (git-svn)

Original comment by cgwalt...@gmail.com on 1 Feb 2008 at 6:24