11from __future__ import unicode_literals
22
3+ from os .path import expanduser , expandvars
4+
5+ from prompt_toolkit .history import FileHistory
6+
37"""
48Copyright OpenSearch Contributors
59SPDX-License-Identifier: Apache-2.0
2125from prompt_toolkit .auto_suggest import AutoSuggestFromHistory
2226from pygments .lexers .sql import SqlLexer
2327
24- from .config import get_config
28+ from .config import get_config , config_location
2529from .opensearch_connection import OpenSearchConnection
2630from .opensearch_buffer import opensearch_is_multiline
2731from .opensearch_style import style_factory , style_factory_output
@@ -57,9 +61,15 @@ def __init__(self, clirc_file=None, always_use_pager=False, use_aws_authenticati
5761 self .multiline_continuation_char = config ["main" ]["multiline_continuation_char" ]
5862 self .multi_line = config ["main" ].as_bool ("multi_line" )
5963 self .multiline_mode = config ["main" ].get ("multi_line_mode" , "src" )
64+ self .history_file = config ["main" ]["history_file" ]
6065 self .null_string = config ["main" ].get ("null_string" , "null" )
6166 self .style_output = style_factory_output (self .syntax_style , self .cli_style )
6267
68+ if self .history_file == "default" :
69+ self .history_file = os .path .join (config_location (), "history" )
70+ else :
71+ self .history_file = expandvars (expanduser (self .history_file ))
72+
6373 def build_cli (self ):
6474 # TODO: Optimize index suggestion to serve indices options only at the needed position, such as 'from'
6575 indices_list = self .opensearch_executor .indices_list
@@ -74,8 +84,7 @@ def get_continuation(width, *_):
7484 lexer = PygmentsLexer (SqlLexer ),
7585 completer = sql_completer ,
7686 complete_while_typing = True ,
77- # TODO: add history, refer to pgcli approach
78- # history=history,
87+ history = FileHistory (self .history_file ),
7988 style = style_factory (self .syntax_style , self .cli_style ),
8089 prompt_continuation = get_continuation ,
8190 multiline = opensearch_is_multiline (self ),
0 commit comments