From 8160c85e446ce3b236d38414eab146e36c2f9673 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Sat, 4 Jan 2014 10:32:33 +0530 Subject: [PATCH 1/4] Updated makefile to install javascript files and partials --- Makefile.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile.in b/Makefile.in index b81206d40..c779ae2b0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -552,6 +552,8 @@ install-force: all install-translations $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man/man1 $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config + $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/js + $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/partials $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts $(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/ $(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/ @@ -575,6 +577,14 @@ install-force: all install-translations $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/; \ true; \ done; + for i in share/tools/web_config/js/*; do\ + $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/js/; \ + true; \ + done; + for i in share/tools/web_config/partials/*; do\ + $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/partials/; \ + true; \ + done; for i in share/tools/web_config/sample_prompts/*.fish; do\ $(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts/; \ true; \ From 02bd933c580ec0015ed298341d0b14cdc8768588 Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 6 Jan 2014 15:06:22 +0800 Subject: [PATCH 2/4] Add Alt+. as a default binding for history-token-search-backward Closes #89. --- share/functions/fish_default_key_bindings.fish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index a46d3f945..a03faaba4 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -89,6 +89,9 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis bind \e\[1\;9B history-token-search-forward # iTerm2 bind \e\[1\;9C forward-word #iTerm2 bind \e\[1\;9D backward-word #iTerm2 + # Bash compatibility + # https://github.com/fish-shell/fish-shell/issues/89 + bind \e. history-token-search-backward bind \ed forward-kill-word bind -k ppage beginning-of-history bind -k npage end-of-history From d20f45b949d194a3fc0c82933670f01983acf24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 8 Jan 2014 20:09:32 +0300 Subject: [PATCH 3/4] fix two minor typos in tutorial --- doc_src/tutorial.hdr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc_src/tutorial.hdr b/doc_src/tutorial.hdr index da9ad6d3f..72f128f2a 100644 --- a/doc_src/tutorial.hdr +++ b/doc_src/tutorial.hdr @@ -312,7 +312,7 @@ lesson.pdf /var/run/sntp.log -

If that directory traversal is taking a long time, you can control-C out of it. +

If that directory traversal is taking a long time, you can Control-C out of it.

Pipes and Redirections

@@ -500,7 +500,7 @@ You can iterate over a list (or a slice) with a for loop: > for val in $PATH echo "entry: $val" end -entry: usr/bin/ +entry: /usr/bin/ entry: /bin entry: /usr/sbin entry: /sbin From 041120aab46ea2336993c728c53600224cb5742c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 8 Jan 2014 15:06:09 -0800 Subject: [PATCH 4/4] Clean up and reduce memory allocations in string escaping --- common.cpp | 132 +++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 76 deletions(-) diff --git a/common.cpp b/common.cpp index 9608e31eb..2b99d1ff2 100644 --- a/common.cpp +++ b/common.cpp @@ -917,61 +917,28 @@ void write_screen(const wcstring &msg, wcstring &buff) buff.push_back(L'\n'); } -/** - Perform string escaping of a strinng by only quoting it. Assumes - the string has already been checked for characters that can not be - escaped this way. - */ -static wchar_t *escape_simple(const wchar_t *in) +/* Escape a string, storing the result in out_str */ +static void escape_string_internal(const wchar_t *orig_in, size_t in_len, wcstring *out_str, escape_flags_t flags) { - wchar_t *out; - size_t len = wcslen(in); - out = (wchar_t *)malloc(sizeof(wchar_t)*(len+3)); - if (!out) - DIE_MEM(); - - out[0] = L'\''; - wcscpy(&out[1], in); - out[len+1]=L'\''; - out[len+2]=0; - return out; -} - -wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) -{ - const wchar_t *in = in_orig; + assert(orig_in != NULL); + const wchar_t *in = orig_in; bool escape_all = !!(flags & ESCAPE_ALL); bool no_quoted = !!(flags & ESCAPE_NO_QUOTED); bool no_tilde = !!(flags & ESCAPE_NO_TILDE); - wchar_t *out; - wchar_t *pos; - int need_escape=0; int need_complex_escape=0; - if (!in) + /* Avoid dereferencing all over the place */ + wcstring &out = *out_str; + + if (!no_quoted && in_len == 0) { - debug(0, L"%s called with null input", __func__); - FATAL_EXIT(); + out.assign(L"''"); + return; } - if (!no_quoted && (wcslen(in) == 0)) - { - out = wcsdup(L"''"); - if (!out) - DIE_MEM(); - return out; - } - - - out = (wchar_t *)malloc(sizeof(wchar_t)*(wcslen(in)*4 + 1)); - pos = out; - - if (!out) - DIE_MEM(); - while (*in != 0) { @@ -981,14 +948,14 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) int val = *in - ENCODE_DIRECT_BASE; int tmp; - *(pos++) = L'\\'; - *(pos++) = L'X'; + out += L'\\'; + out += L'X'; tmp = val/16; - *pos++ = tmp > 9? L'a'+(tmp-10):L'0'+tmp; + out += tmp > 9? L'a'+(tmp-10):L'0'+tmp; tmp = val%16; - *pos++ = tmp > 9? L'a'+(tmp-10):L'0'+tmp; + out += tmp > 9? L'a'+(tmp-10):L'0'+tmp; need_escape=need_complex_escape=1; } @@ -998,32 +965,32 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) switch (c) { case L'\t': - *(pos++) = L'\\'; - *(pos++) = L't'; + out += L'\\'; + out += L't'; need_escape=need_complex_escape=1; break; case L'\n': - *(pos++) = L'\\'; - *(pos++) = L'n'; + out += L'\\'; + out += L'n'; need_escape=need_complex_escape=1; break; case L'\b': - *(pos++) = L'\\'; - *(pos++) = L'b'; + out += L'\\'; + out += L'b'; need_escape=need_complex_escape=1; break; case L'\r': - *(pos++) = L'\\'; - *(pos++) = L'r'; + out += L'\\'; + out += L'r'; need_escape=need_complex_escape=1; break; case L'\x1b': - *(pos++) = L'\\'; - *(pos++) = L'e'; + out += L'\\'; + out += L'e'; need_escape=need_complex_escape=1; break; @@ -1033,8 +1000,8 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) { need_escape=need_complex_escape=1; if (escape_all) - *pos++ = L'\\'; - *pos++ = *in; + out += L'\\'; + out += *in; break; } @@ -1063,9 +1030,9 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) { need_escape=1; if (escape_all) - *pos++ = L'\\'; + out += L'\\'; } - *pos++ = *in; + out += *in; break; } @@ -1075,9 +1042,9 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) { if (*in <27 && *in > 0) { - *(pos++) = L'\\'; - *(pos++) = L'c'; - *(pos++) = L'a' + *in -1; + out += L'\\'; + out += L'c'; + out += L'a' + *in -1; need_escape=need_complex_escape=1; break; @@ -1086,15 +1053,15 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) int tmp = (*in)%16; - *pos++ = L'\\'; - *pos++ = L'x'; - *pos++ = ((*in>15)? L'1' : L'0'); - *pos++ = tmp > 9? L'a'+(tmp-10):L'0'+tmp; + out += L'\\'; + out += L'x'; + out += ((*in>15)? L'1' : L'0'); + out += tmp > 9? L'a'+(tmp-10):L'0'+tmp; need_escape=need_complex_escape=1; } else { - *pos++ = *in; + out += *in; } break; } @@ -1103,7 +1070,6 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) in++; } - *pos = 0; /* Use quoted escaping if possible, since most people find it @@ -1111,18 +1077,32 @@ wchar_t *escape(const wchar_t *in_orig, escape_flags_t flags) */ if (!no_quoted && need_escape && !need_complex_escape && escape_all) { - free(out); - out = escape_simple(in_orig); + wchar_t single_quote = L'\''; + out.clear(); + out.reserve(2 + in_len); + out.push_back(single_quote); + out.append(orig_in, in_len); + out.push_back(single_quote); + } +} + +wchar_t *escape(const wchar_t *in, escape_flags_t flags) +{ + if (!in) + { + debug(0, L"%s called with null input", __func__); + FATAL_EXIT(); } - return out; + wcstring tmp; + escape_string_internal(in, wcslen(in), &tmp, flags); + return wcsdup(tmp.c_str()); } wcstring escape_string(const wcstring &in, escape_flags_t flags) { - wchar_t *tmp = escape(in.c_str(), flags); - wcstring result(tmp); - free(tmp); + wcstring result; + escape_string_internal(in.c_str(), in.size(), &result, flags); return result; }