aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/vi.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/editors/vi.c b/editors/vi.c
index cc4f6bde7..e6527e36b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -7,7 +7,7 @@
7 */ 7 */
8// 8//
9//Things To Do: 9//Things To Do:
10// $HOME/.exrc and ./.exrc 10// ./.exrc
11// add magic to search /foo.*bar 11// add magic to search /foo.*bar
12// add :help command 12// add :help command
13// :map macros 13// :map macros
@@ -185,7 +185,7 @@
185//usage:#define vi_full_usage "\n\n" 185//usage:#define vi_full_usage "\n\n"
186//usage: "Edit FILE\n" 186//usage: "Edit FILE\n"
187//usage: IF_FEATURE_VI_COLON( 187//usage: IF_FEATURE_VI_COLON(
188//usage: "\n -c CMD Initial command to run ($EXINIT also available)" 188//usage: "\n -c CMD Initial command to run ($EXINIT and ~/.exrc also available)"
189//usage: ) 189//usage: )
190//usage: IF_FEATURE_VI_READONLY( 190//usage: IF_FEATURE_VI_READONLY(
191//usage: "\n -R Read-only" 191//usage: "\n -R Read-only"
@@ -2829,10 +2829,12 @@ static void colon(char *buf)
2829 // :!<cmd> // run <cmd> then return 2829 // :!<cmd> // run <cmd> then return
2830 // 2830 //
2831 2831
2832 if (!buf[0]) 2832 while (*buf == ':')
2833 goto ret; 2833 buf++; // move past leading colons
2834 if (*buf == ':') 2834 while (isblank(*buf))
2835 buf++; // move past the ':' 2835 buf++; // move past leading blanks
2836 if (!buf[0] || buf[0] == '"')
2837 goto ret; // ignore empty lines or those starting with '"'
2836 2838
2837 li = i = 0; 2839 li = i = 0;
2838 b = e = -1; 2840 b = e = -1;
@@ -4923,14 +4925,37 @@ int vi_main(int argc, char **argv)
4923 cmdline_filecnt = argc - optind; 4925 cmdline_filecnt = argc - optind;
4924 4926
4925 // 1- process EXINIT variable from environment 4927 // 1- process EXINIT variable from environment
4926 // 2- if EXINIT is unset process $HOME/.exrc file (not implemented yet) 4928 // 2- if EXINIT is unset process $HOME/.exrc file
4927 // 3- process command line args 4929 // 3- process command line args
4928#if ENABLE_FEATURE_VI_COLON 4930#if ENABLE_FEATURE_VI_COLON
4929 { 4931 {
4930 const char *exinit = getenv("EXINIT"); 4932 const char *exinit = getenv("EXINIT");
4933 char *cmds = NULL;
4931 4934
4932 if (exinit) { 4935 if (exinit) {
4933 char *cmds = xstrdup(exinit); 4936 cmds = xstrdup(exinit);
4937 } else {
4938 const char *home = getenv("HOME");
4939
4940 if (home && *home) {
4941 char *exrc = concat_path_file(home, ".exrc");
4942 struct stat st;
4943
4944 // .exrc must belong to and only be writable by user
4945 if (stat(exrc, &st) == 0) {
4946 if ((st.st_mode & (S_IWGRP|S_IWOTH)) == 0
4947 && st.st_uid == getuid()
4948 ) {
4949 cmds = xmalloc_open_read_close(exrc, NULL);
4950 } else {
4951 status_line_bold(".exrc: permission denied");
4952 }
4953 }
4954 free(exrc);
4955 }
4956 }
4957
4958 if (cmds) {
4934 init_text_buffer(NULL); 4959 init_text_buffer(NULL);
4935 run_cmds(cmds); 4960 run_cmds(cmds);
4936 free(cmds); 4961 free(cmds);