]> git.phdru.name Git - dotfiles.git/blobdiff - .vimrc
.vimrc: Rename Xbit to ToggleXbit
[dotfiles.git] / .vimrc
diff --git a/.vimrc b/.vimrc
index d743be717f83686b9ed92935f7260d87224116f9..1620a5d40ad0b78cd52e498f9a6807d38dbfce5e 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -586,25 +586,26 @@ endif
 " From Tip 212:
 " http://vim.wikia.com/wiki/Setting_file_attributes_without_reloading_a_buffer
 
-function! SetExecutableBit(x)
-   if !executable('chmod')
-      return
-   endif
-   checktime
-   let fname = expand("%:p")
-   execute "au FileChangedShell " . fname . " :echo"
-   if a:x
-      silent !chmod a+x %
-   else
-      silent !chmod a-x %
-   endif
-   if v:shell_error
-      echoerr 'Error running chmod: ' . v:shell_error
-   endif
-   checktime
-   execute "au! FileChangedShell " . fname
-endfunction
-command! Xbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
+if executable('chmod')
+   function! SetExecutableBit(x)
+      checktime
+      let fname = expand("%:p")
+      let fx = executable(fname)
+      execute "au FileChangedShell " . fname . " :echo"
+      if a:x && !fx
+         !chmod a+x %
+      elseif !a:x && fx
+         !chmod a-x %
+      endif
+      if v:shell_error
+         echoerr 'Error running chmod: ' . v:shell_error
+      endif
+      checktime
+      execute "au! FileChangedShell " . fname
+   endfunction
+   command! ToggleXbit if executable(expand("%:p")) | call SetExecutableBit(0) | else | call SetExecutableBit(1) | endif
+endif
+
 
 " ----------
 " From http://slobin.pp.ru/vim/_vimrc.html