web_config: improve abbreviations support

* Fetch abbreviations by reading the variable directly.
 * Use space separators for writing new abbreviations.

Work on #731.
This commit is contained in:
David Adam 2014-11-16 23:19:53 +08:00
parent 14fa48864a
commit 9aaf93f364

View file

@ -687,16 +687,11 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return result return result
def do_get_abbreviations(self): def do_get_abbreviations(self):
out, err = run_fish_cmd('abbr -s') out, err = run_fish_cmd('echo -n -s $fish_user_abbreviations\x1e')
lines = (x for x in out.rstrip().split('\n'))
# Turn the output into something we can use
abbrout = (line[len('abbr -a '):].strip('\'') for line in lines)
abbrs = [re.split('[ =]', x, maxsplit=1) for x in abbrout]
if abbrs[0][0]: lines = (x for x in out.rstrip().split('\x1e'))
result = [{'word': x, 'phrase': y} for x, y in abbrs] abbrs = (re.split('[ =]', x, maxsplit=1) for x in lines if x)
else: result = [{'word': x, 'phrase': y} for x, y in abbrs]
result = []
return result return result
def do_remove_abbreviation(self, abbreviation): def do_remove_abbreviation(self, abbreviation):
@ -707,7 +702,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return True return True
def do_save_abbreviation(self, abbreviation): def do_save_abbreviation(self, abbreviation):
out, err = run_fish_cmd('abbr -a \'%s=%s\'' % (abbreviation['word'], abbreviation['phrase'])) out, err = run_fish_cmd('abbr -a \'%s %s\'' % (abbreviation['word'], abbreviation['phrase']))
if err: if err:
return err return err
else: else: