File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ def get_aliases(self):
6565 return dict (self ._parse_alias (alias )
6666 for alias in raw_aliases if alias and '=' in alias )
6767
68+ def get_history (self ):
69+ return list (self ._get_history_lines ())
70+
6871 def _get_history_file_name (self ):
6972 return os .environ .get ("HISTFILE" ,
7073 os .path .expanduser ('~/.bash_history' ))
Original file line number Diff line number Diff line change 88from ..const import ARGUMENT_PLACEHOLDER
99from ..utils import DEVNULL , cache
1010from .generic import Generic
11+ import io
1112
1213
1314@cache ('~/.config/fish/config.fish' , '~/.config/fish/functions' )
@@ -72,6 +73,22 @@ def get_aliases(self):
7273 functions .update (raw_aliases )
7374 return functions
7475
76+ def get_history (self ):
77+ history_file_name = self ._get_history_file_name ()
78+ if not os .path .isfile (history_file_name ):
79+ return
80+
81+ try :
82+ with io .open (history_file_name , 'r' ) as history :
83+ for line in history .readlines ():
84+ line = line .strip ()
85+ if line .startswith ('- cmd:' ):
86+ cmd = line [len ('- cmd:' ):].strip ()
87+ if cmd :
88+ yield cmd
89+ except (OSError , IOError ):
90+ return
91+
7592 def _expand_aliases (self , command_script ):
7693 aliases = self .get_aliases ()
7794 binary = command_script .split (' ' )[0 ]
Original file line number Diff line number Diff line change @@ -49,27 +49,30 @@ def _get_history_file_name(self):
4949 def _get_history_line (self , command_script ):
5050 return ''
5151
52- @memoize
5352 def get_history (self ):
5453 return list (self ._get_history_lines ())
5554
5655 def _get_history_lines (self ):
57- """Returns list of history entries."""
5856 history_file_name = self ._get_history_file_name ()
59- if os .path .isfile (history_file_name ):
57+
58+ if not history_file_name :
59+ return []
60+
61+ if os .path .exists (history_file_name ):
6062 with io .open (history_file_name , 'r' ,
61- encoding = 'utf-8' , errors = 'ignore' ) as history_file :
63+ encoding = 'utf-8' , errors = 'ignore' ) as history_file :
6264
6365 lines = history_file .readlines ()
6466 if settings .history_limit :
6567 lines = lines [- settings .history_limit :]
6668
6769 for line in lines :
68- prepared = self ._script_from_history (line ) \
69- .strip ()
70+ prepared = self ._script_from_history (line ).strip ()
7071 if prepared :
7172 yield prepared
7273
74+ return []
75+
7376 def and_ (self , * commands ):
7477 return u' && ' .join (commands )
7578
Original file line number Diff line number Diff line change 33import os
44from ..utils import DEVNULL , memoize
55from .generic import Generic
6+ import io
67
78
89class Tcsh (Generic ):
@@ -25,6 +26,20 @@ def get_aliases(self):
2526 for alias in proc .stdout .read ().decode ('utf-8' ).split ('\n ' )
2627 if alias and '\t ' in alias )
2728
29+ def get_history (self ):
30+ history_file_name = self ._get_history_file_name ()
31+ if not os .path .isfile (history_file_name ):
32+ return
33+
34+ try :
35+ with io .open (history_file_name , 'r' ) as history :
36+ for line in history .readlines ():
37+ line = line .strip ()
38+ if line and not line .startswith ('#+' ):
39+ yield line
40+ except (OSError , IOError ):
41+ return
42+
2843 def _get_history_file_name (self ):
2944 return os .environ .get ("HISTFILE" ,
3045 os .path .expanduser ('~/.history' ))
You can’t perform that action at this time.
0 commit comments