* Christ van Willegen <cvwillegen@> [060816 13:33]:
That should have been:
+ :call system("chmod +x -- " . shellescape(expand("%")))
Oops! Thanks. -- Regards, Sir Raorn. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFE4umWVqT7+fkT8woRAsGaAKCkmNRue9UjjNzCSfMWJolqfFehJACffwjP nLKfmjp9UQfbrZ9+BgAhwtw= =c8fI -----END PGP SIGNATURE-----
diff -crNp ../vim70.orig/runtime/doc/eval.txt ./runtime/doc/eval.txt *** ../vim70.orig/runtime/doc/eval.txt Sun May 7 16:16:44 2006 --- ./runtime/doc/eval.txt Wed Aug 16 12:43:40 2006 *************** *** 1,4 **** ! *eval.txt* For Vim version 7.0. Last change: 2006 May 06 VIM REFERENCE MANUAL by Bram Moolenaar --- 1,4 ---- ! *eval.txt* For Vim version 7.0. Last change: 2006 Aug 16 VIM REFERENCE MANUAL by Bram Moolenaar *************** setreg( {n}, {v}[, {opt}]) Number set re *** 1709,1714 **** --- 1709,1716 ---- settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window {winnr} in tab page {tabnr} to {val} setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} + shellescape( {string}) String escape {string} for use as shell + command argument simplify( {filename}) String simplify filename as much as possible sort( {list} [, {func}]) List sort {list}, using {func} to compare soundfold( {word}) String sound-fold {word} *************** setwinvar({nr}, {varname}, {val}) *set *** 4434,4439 **** --- 4436,4454 ---- :call setwinvar(1, "&list", 0) :call setwinvar(2, "myvar", "foobar") + shellescape({string}) *shellescape()* + Escape {string} for use as shell command argument. + On Unix, it will enclose {string} in single quotes and replace + all "'" with "'\''" within {string}. + On Windows and DOS, it will enclose {string} double quotes and + strip all double quotes within {string}. + On other platforms untouched {string} is returned. + Example: > + :echo shellescape('c:\program files\vim') + < results in: > + "c:\program files\vim" + < Example usage: > + :call system("chmod +x -- " . shellescape(expand("%"))) simplify({filename}) *simplify()* Simplify the file name as much as possible without changing the meaning. Shortcuts (on MS-Windows) or symbolic links (on diff -crNp ../vim70.orig/runtime/doc/tags ./runtime/doc/tags *** ../vim70.orig/runtime/doc/tags Sun May 7 17:33:26 2006 --- ./runtime/doc/tags Wed Aug 16 12:42:26 2006 *************** sftp pi_netrw.txt /*sftp* *** 6831,6836 **** --- 6831,6837 ---- sgml.vim syntax.txt /*sgml.vim* sh.vim syntax.txt /*sh.vim* shell-window tips.txt /*shell-window* + shellescape() eval.txt /*shellescape()* shell_error-variable eval.txt /*shell_error-variable* shift intro.txt /*shift* shift-left-right change.txt /*shift-left-right* diff -crNp ../vim70.orig/src/eval.c ./src/eval.c *** ../vim70.orig/src/eval.c Wed Aug 16 11:44:57 2006 --- ./src/eval.c Wed Aug 16 11:46:14 2006 *************** static void f_setqflist __ARGS((typval_T *** 622,627 **** --- 622,628 ---- static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv)); static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv)); static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv)); + static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv)); static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv)); static void f_sort __ARGS((typval_T *argvars, typval_T *rettv)); static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv)); *************** static struct fst *** 7139,7144 **** --- 7140,7146 ---- {"setreg", 2, 3, f_setreg}, {"settabwinvar", 4, 4, f_settabwinvar}, {"setwinvar", 3, 3, f_setwinvar}, + {"shellescape", 1, 1, f_shellescape}, {"simplify", 1, 1, f_simplify}, {"sort", 1, 2, f_sort}, {"soundfold", 1, 1, f_soundfold}, *************** setwinvar(argvars, rettv, off) *** 14609,14614 **** --- 14611,14630 ---- } /* + * "shellescape({string})" function + */ + static void + f_shellescape(argvars, rettv) + typval_T *argvars; + typval_T *rettv; + { + char_u buf[NUMBUFLEN]; + + rettv->vval.v_string = vim_strsave_shell_escape(get_tv_string(&argvars[0])); + rettv->v_type = VAR_STRING; + } + + /* * "simplify()" function */ static void diff -crNp ../vim70.orig/src/misc2.c ./src/misc2.c *** ../vim70.orig/src/misc2.c Thu May 4 16:12:38 2006 --- ./src/misc2.c Wed Aug 16 12:27:27 2006 *************** vim_strsave_escaped_ext(string, esc_char *** 1230,1235 **** --- 1230,1336 ---- } /* + * Like vim_strsave_escaped(), but escape string for use as command + * argument in system(). + */ + char_u * + vim_strsave_shell_escape(string) + char_u *string; + { + char_u *p; + char_u *p2; + char_u *escaped_string; + unsigned length; + #ifdef FEAT_MBYTE + int l; + #endif + + /* + * First count the number of escaped characters required. + * Then allocate the memory and insert them. + */ + length = 3; /* two quotes and the trailing NUL */ + for (p = string; *p; p++) + { + #ifdef FEAT_MBYTE + if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) + { + length += l; /* count a multibyte char */ + p += l - 1; + continue; + } + #endif + switch (*p) + { + #if defined(WIN32) || defined(WIN16) || defined(DOS) + case '"': + break; /* strip quotes */ + #else + # if defined(UNIX) + case '\'': + length+=4; /* ' => '\'' */ + break; + # endif + #endif + default: + ++length; /* count an ordinary char */ + break; + } + } + escaped_string = alloc(length); + if (escaped_string != NULL) + { + p2 = escaped_string; + #if defined(WIN32) || defined(WIN16) || defined(DOS) + *p2++ = '"'; + #else + # if defined(UNIX) + *p2++ = '\''; + # endif + #endif + for (p = string; *p; p++) + { + #ifdef FEAT_MBYTE + if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) + { + mch_memmove(p2, p, (size_t)l); + p2 += l; + p += l - 1; /* skip multibyte char */ + continue; + } + #endif + switch (*p) { + #if defined(WIN32) || defined(WIN16) || defined(DOS) + case '"': + break; /* strip quotes */ + #else + # if defined(UNIX) + case '\'': + *p2++='\''; + *p2++='\\'; + *p2++='\''; + *p2++='\''; + break; + # endif + #endif + default: + *p2++ = *p; + break; + } + } + #if defined(WIN32) || defined(WIN16) || defined(DOS) + *p2++ = '"'; + #else + # if defined(UNIX) + *p2++ = '\''; + # endif + #endif + *p2 = NUL; + } + return escaped_string; + } + + /* * Like vim_strsave(), but make all characters uppercase. * This uses ASCII lower-to-upper case translation, language independent. */