Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
in vifm by

I've tried a few variations of this and don't see any examples or questions about it.

\| command togglex :
\|   if test -x %c
\|     chmod -x %c
\|   else
\|     chmod +x %c
\|   endif

" Toggle executable
" map * <nop>
map \* togglex

1 Answer

+1 vote
by
selected by
 
Best answer

There is no test command/function, need to use system() for that:

command togglex :
\|   if system(expand('test -x %%c && echo x')) == 'x'
\|     chmod -x
\|   else
\|     chmod +x
\|   endif

nnoremap <silent> * :togglex<cr>

don't see any examples or questions about it

Toggling a permission seems uncommon to me.

by

Thank you!
I'm coming from jarun/nnn where this is a feature
I'm on debian so there are some shell scripts or AppImages I install that require this step.

by

I like the idea of having a key binding to toggle the execute bit, since I do this fairly often.

I've expanded the command slightly to allow two key bindings: one that toggles the execute bit for just the user, and another that toggles it for all (user, group, and other).

command! ToggleExecuteBit
  \ : if system( expand( 'test -x %%c && echo "x"' ) ) == 'x'
  \ |   if %a == 'user' | chmod u-x | elseif %a == 'all' | chmod -x | endif
  \ | else
  \ |   if %a == 'user' | chmod u+x | elseif %a == 'all' | chmod +x | endif
  \ | endif

nnoremap <silent> <A-x>   :ToggleExecuteBit 'user'<CR>
nnoremap <silent> <A-S-x> :ToggleExecuteBit 'all'<CR>
If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...