diff --git a/share/tools/web_config/partials/prompt.html b/share/tools/web_config/partials/prompt.html
index e11da923c..fed161413 100644
--- a/share/tools/web_config/partials/prompt.html
+++ b/share/tools/web_config/partials/prompt.html
@@ -1,10 +1,20 @@
-
+
+
+
{{ selectedPrompt.name }}
+
+
+ {{ savePromptButtonTitle }}
+
+
+
Select a prompt below:
+
diff --git a/share/tools/web_config/sample_prompts/classic.fish b/share/tools/web_config/sample_prompts/classic.fish
index 9464b778f..64c2fb500 100644
--- a/share/tools/web_config/sample_prompts/classic.fish
+++ b/share/tools/web_config/sample_prompts/classic.fish
@@ -12,7 +12,7 @@ function fish_prompt --description "Write out the prompt"
switch $USER
- case root
+ case root toor
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
diff --git a/share/tools/web_config/sample_prompts/classic_git.fish b/share/tools/web_config/sample_prompts/classic_git.fish
index 0d91f5fe0..299faa34a 100644
--- a/share/tools/web_config/sample_prompts/classic_git.fish
+++ b/share/tools/web_config/sample_prompts/classic_git.fish
@@ -43,7 +43,7 @@ function fish_prompt --description 'Write out the prompt'
switch $USER
- case root
+ case root toor
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
diff --git a/share/tools/web_config/sample_prompts/classic_status.fish b/share/tools/web_config/sample_prompts/classic_status.fish
index a93ff9f22..4b062c5da 100644
--- a/share/tools/web_config/sample_prompts/classic_status.fish
+++ b/share/tools/web_config/sample_prompts/classic_status.fish
@@ -22,7 +22,7 @@ function fish_prompt --description 'Write out the prompt'
set -l user_prompt '>'
switch $USER
# Set our root colors, if we're root :)
- case root
+ case root toor
set user_prompt '#'
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
diff --git a/share/tools/web_config/sample_prompts/debian_chroot.fish b/share/tools/web_config/sample_prompts/debian_chroot.fish
index d800c7441..80acfa9a5 100644
--- a/share/tools/web_config/sample_prompts/debian_chroot.fish
+++ b/share/tools/web_config/sample_prompts/debian_chroot.fish
@@ -31,7 +31,7 @@ function fish_prompt --description 'Write out the prompt, prepending the Debian
switch $USER
- case root
+ case root toor
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
diff --git a/share/tools/web_config/sample_prompts/informative.fish b/share/tools/web_config/sample_prompts/informative.fish
index 9095b740f..b0bc601b3 100644
--- a/share/tools/web_config/sample_prompts/informative.fish
+++ b/share/tools/web_config/sample_prompts/informative.fish
@@ -27,7 +27,7 @@ if not set -q __fish_color_blue
switch $USER
-case root
+case root toor
if not set -q __fish_prompt_cwd
if set -q fish_color_cwd_root
@@ -48,4 +48,4 @@ if not set -q __fish_prompt_cwd
printf '[%s] %s%s@%s %s%s %s(%s)%s \f\r> ' (date "+%H:%M:%S") "$__fish_color_blue" $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (pwd) "$__fish_color_status" "$stat" "$__fish_prompt_normal"
end
-end
\ No newline at end of file
+end
diff --git a/share/tools/web_config/sample_prompts/nim.fish b/share/tools/web_config/sample_prompts/nim.fish
index 6eab39e68..87837bf86 100644
--- a/share/tools/web_config/sample_prompts/nim.fish
+++ b/share/tools/web_config/sample_prompts/nim.fish
@@ -13,7 +13,7 @@ function fish_prompt
end
set_color -o green
echo -n [
- if [ $USER = root ]
+ if test $USER = root -o $USER = toor
set_color -o red
else
set_color -o yellow
diff --git a/share/tools/web_config/sample_prompts/user_host_path.fish b/share/tools/web_config/sample_prompts/user_host_path.fish
index c125eea0c..de917ee71 100644
--- a/share/tools/web_config/sample_prompts/user_host_path.fish
+++ b/share/tools/web_config/sample_prompts/user_host_path.fish
@@ -6,7 +6,7 @@ function fish_prompt -d "Write out the prompt"
set -l pwd (echo -n $PWD | sed "s/^$home_escaped/~/" | sed 's/ /%20/g')
set -l prompt_symbol ''
switch $USER
- case root; set prompt_symbol '#'
+ case root toor; set prompt_symbol '#'
case '*'; set prompt_symbol '$'
end
printf "[%s@%s %s%s%s]%s " $USER (hostname -s) (set_color $fish_color_cwd) $pwd (set_color normal) $prompt_symbol
diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py
index fec78af97..c3daef5fe 100755
--- a/share/tools/web_config/webconfig.py
+++ b/share/tools/web_config/webconfig.py
@@ -1,7 +1,10 @@
#!/usr/bin/env python
# Whether we're Python 2
-import sys, os
+import sys
+import multiprocessing.pool
+import os
+import operator
IS_PY2 = sys.version_info[0] == 2
if IS_PY2:
@@ -29,8 +32,6 @@ try:
except ImportError:
import simplejson as json
-from optparse import OptionParser
-
FISH_BIN_PATH = False # will be set later
def run_fish_cmd(text):
from subprocess import PIPE
@@ -287,7 +288,7 @@ class BindingParser:
def set_buffer(self, buffer):
""" Sets code to parse """
- self.buffer = buffer
+ self.buffer = buffer or b''
self.index = 0
def get_char(self):
@@ -489,7 +490,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
result.append([color_name, color_desc, parse_color('')])
# Sort our result (by their keys)
- result.sort()
+ result.sort(key=operator.itemgetter('name'))
return result
@@ -545,29 +546,22 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
bindings = []
binding_parser = BindingParser()
- parser = OptionParser()
- parser.add_option("-k")
- parser.add_option("-M")
- parser.add_option("-m")
-
- # Ignore any parsing errors
- parser.error = lambda x: None
-
for line in out.split('\n'):
- comps = line.split(' ', 1)
+ comps = line.split(' ', 2)
- if len(comps) < 2:
+ if len(comps) < 3:
continue
- # parse arguments passed to bind command
- bind_args_list = comps[1].split(' ', 6)
- (options, args) = parser.parse_args(bind_args_list)
+ if comps[1] == '-k':
+ key_name, command = comps[2].split(' ', 1)
+ binding_parser.set_buffer(key_name)
+ else:
+ key_name = None
+ command = comps[2]
+ binding_parser.set_buffer(comps[1])
- key_name= options.k
- command = args[0]
-
- binding_parser.set_buffer(key_name)
- fish_binding = FishBinding(command=command, binding=key_name, readable_binding=binding_parser.get_readable_binding())
+ readable_binding = binding_parser.get_readable_binding()
+ fish_binding = FishBinding(command, key_name, readable_binding)
bindings.append(fish_binding)
return [ binding.get_json_obj() for binding in bindings ]
@@ -611,22 +605,27 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
out, err = run_fish_cmd(cmd)
return len(err) == 0
- def do_get_prompt(self, command_to_run, prompt_function_text):
+ def do_get_prompt(self, command_to_run, prompt_function_text, extras_dict):
# Return the prompt output by the given command
prompt_demo_ansi, err = run_fish_cmd(command_to_run)
prompt_demo_html = ansi_to_html(prompt_demo_ansi)
prompt_demo_font_size = self.font_size_for_ansi_prompt(prompt_demo_ansi)
- return {'function': prompt_function_text, 'demo': prompt_demo_html, 'font_size': prompt_demo_font_size }
+ result = {'function': prompt_function_text, 'demo': prompt_demo_html, 'font_size': prompt_demo_font_size }
+ if extras_dict:
+ result.update(extras_dict)
+ return result
def do_get_current_prompt(self):
# Return the current prompt
prompt_func, err = run_fish_cmd('functions fish_prompt')
- return self.do_get_prompt('cd "' + initial_wd + '" ; fish_prompt', prompt_func.strip())
+ result = self.do_get_prompt('builtin cd "' + initial_wd + '" ; fish_prompt', prompt_func.strip(), {'name': 'Current'})
+ return result
- def do_get_sample_prompt(self, text):
+ def do_get_sample_prompt(self, text, extras_dict):
# Return the prompt you get from the given text
+ # extras_dict is a dictionary whose values get merged in
cmd = text + "\n cd \"" + initial_wd + "\" \n fish_prompt\n"
- return self.do_get_prompt(cmd, text.strip())
+ return self.do_get_prompt(cmd, text.strip(), extras_dict)
def parse_one_sample_prompt_hash(self, line, result_dict):
# Allow us to skip whitespace, etc.
@@ -644,38 +643,41 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return line.startswith('#')
- def read_one_sample_prompt(self, fd):
- # Read one sample prompt from fd
- function_lines = []
- result = {}
- parsing_hashes = True
- for line in fd:
- # Parse hashes until parse_one_sample_prompt_hash return False
- if parsing_hashes:
- parsing_hashes = self.parse_one_sample_prompt_hash(line, result)
- # Maybe not we're not parsing hashes, or maybe we already were not
- if not parsing_hashes:
- function_lines.append(line)
- func = ''.join(function_lines).strip()
- result.update(self.do_get_sample_prompt(func))
- return result
+ def read_one_sample_prompt(self, path):
+ try:
+ with open(path) as fd:
+ extras_dict = {}
+ # Read one sample prompt from fd
+ function_lines = []
+ parsing_hashes = True
+ for line in fd:
+ # Parse hashes until parse_one_sample_prompt_hash return False
+ if parsing_hashes:
+ parsing_hashes = self.parse_one_sample_prompt_hash(line, extras_dict)
+ # Maybe not we're not parsing hashes, or maybe we already were not
+ if not parsing_hashes:
+ function_lines.append(line)
+ func = ''.join(function_lines).strip()
+ result = self.do_get_sample_prompt(func, extras_dict)
+ return result
+ except IOError:
+ # Ignore unreadable files, etc.
+ return None
def do_get_sample_prompts_list(self):
- result = []
- # Start with the "Current" meta-sample
- result.append({'name': 'Current'})
- result[0].update(self.do_get_current_prompt())
+ pool = multiprocessing.pool.ThreadPool(processes=8)
+
+ # Kick off the "Current" meta-sample
+ current_metasample_async = pool.apply_async(self.do_get_current_prompt)
# Read all of the prompts in sample_prompts
paths = glob.iglob('sample_prompts/*.fish')
- for path in paths:
- try:
- fd = open(path)
- result.append(self.read_one_sample_prompt(fd))
- fd.close()
- except IOError:
- # Ignore unreadable files, etc
- pass
+ sample_results = pool.map(self.read_one_sample_prompt, paths, 1)
+
+ # Finish up
+ result = []
+ result.append(current_metasample_async.get())
+ result.extend([r for r in sample_results if r])
return result
def font_size_for_ansi_prompt(self, prompt_demo_ansi):
@@ -705,8 +707,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
output = self.do_get_history()
# end = time.time()
# print "History: ", end - start
- elif p == '/current_prompt/':
- output = self.do_get_current_prompt()
elif p == '/sample_prompts/':
output = self.do_get_sample_prompts_list()
elif re.match(r"/color/(\w+)/", p):
@@ -761,9 +761,6 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
elif p == '/get_function/':
what = postvars.get('what')
output = [self.do_get_function(what[0])]
- elif p == '/get_sample_prompt/':
- what = postvars.get('what')
- output = [self.do_get_sample_prompt(what[0])]
elif p == '/delete_history_item/':
what = postvars.get('what')
if self.do_delete_history_item(what[0]):
diff --git a/tests/history_sample_corrupt1 b/tests/history_sample_corrupt1
new file mode 100644
index 000000000..3dfe694fa
--- /dev/null
+++ b/tests/history_sample_corrupt1
@@ -0,0 +1,5 @@
+- cmd: this_command_is_ok
+- cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: when: 1396531614
+- cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: - cmd: corrupt_prefix
+- cmd: no_newline_at_end_of_file
+ when: 1403531898
\ No newline at end of file