2016-12-27 16:05:41 +00:00
|
|
|
# interpreter for shell commands (needs to be POSIX compatible)
|
2018-02-17 17:04:30 +00:00
|
|
|
set shell sh
|
2016-08-27 11:12:03 +00:00
|
|
|
|
2018-06-26 19:24:41 +00:00
|
|
|
# set '-eu' options for shell commands
|
|
|
|
# These options are used to have safer shell commands. Option '-e' is used to
|
2018-06-27 18:15:34 +00:00
|
|
|
# exit on error and option '-u' is used to give error for unset variables.
|
2018-06-26 19:24:41 +00:00
|
|
|
# Option '-f' disables pathname expansion which can be useful when $f, $fs, and
|
|
|
|
# $fx variables contain names with '*' or '?' characters. However, this option
|
|
|
|
# is used selectively within individual commands as it can be limiting at
|
|
|
|
# times.
|
|
|
|
set shellopts '-eu'
|
|
|
|
|
2017-09-07 20:01:57 +00:00
|
|
|
# set internal field separator (IFS) to "\n" for shell commands
|
|
|
|
# This is useful to automatically split file names in $fs and $fx properly
|
2017-09-08 20:46:31 +00:00
|
|
|
# since default file separator used in these variables (i.e. 'filesep' option)
|
2017-09-07 20:01:57 +00:00
|
|
|
# is newline. You need to consider the values of these options and create your
|
|
|
|
# commands accordingly.
|
|
|
|
set ifs "\n"
|
2016-08-27 14:17:20 +00:00
|
|
|
|
2016-08-13 12:49:04 +00:00
|
|
|
# leave some space at the top and the bottom of the screen
|
|
|
|
set scrolloff 10
|
|
|
|
|
|
|
|
# use enter for shell commands
|
2018-03-27 18:23:34 +00:00
|
|
|
map <enter> shell
|
2016-08-13 12:49:04 +00:00
|
|
|
|
|
|
|
# execute current file (must be executable)
|
2017-09-07 20:01:57 +00:00
|
|
|
map x $$f
|
|
|
|
map X !$f
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2016-08-24 22:12:22 +00:00
|
|
|
# dedicated keys for file opener actions
|
2017-09-07 20:01:57 +00:00
|
|
|
map o &mimeopen $f
|
|
|
|
map O $mimeopen --ask $f
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2018-06-28 18:20:43 +00:00
|
|
|
# define a custom 'open' command
|
|
|
|
# This command is called when current file is not a directory. You may want to
|
|
|
|
# use either file extensions and/or mime types here. Below uses an editor for
|
|
|
|
# text files and a file opener for the rest.
|
|
|
|
cmd open ${{
|
2017-09-07 20:01:57 +00:00
|
|
|
case $(file --mime-type $f -b) in
|
2018-06-28 18:53:42 +00:00
|
|
|
text/*) $EDITOR $fx;;
|
|
|
|
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
2016-08-24 22:12:22 +00:00
|
|
|
esac
|
|
|
|
}}
|
|
|
|
|
2016-08-13 12:49:04 +00:00
|
|
|
# rename current file without overwrite
|
2018-04-06 19:49:50 +00:00
|
|
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
2016-10-15 18:46:31 +00:00
|
|
|
map r push :rename<space>
|
2016-08-13 12:49:04 +00:00
|
|
|
|
|
|
|
# make sure trash folder exists
|
2018-04-06 19:49:50 +00:00
|
|
|
%mkdir -p ~/.trash
|
2016-08-13 12:49:04 +00:00
|
|
|
|
|
|
|
# move current file or selected files to trash folder
|
2017-09-16 19:11:43 +00:00
|
|
|
# (also see 'man mv' for backup/overwrite options)
|
2018-06-26 19:24:41 +00:00
|
|
|
cmd trash %set -f; mv $fx ~/.trash
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2018-06-28 18:55:56 +00:00
|
|
|
# delete current file or selected files (prompting)
|
|
|
|
cmd delete ${{
|
2018-06-26 19:24:41 +00:00
|
|
|
set -f
|
2017-09-08 20:46:31 +00:00
|
|
|
printf "$fx\n"
|
2018-06-28 18:55:56 +00:00
|
|
|
printf "delete?[y/n]"
|
2017-09-08 20:46:31 +00:00
|
|
|
read ans
|
|
|
|
[ $ans = "y" ] && rm -rf $fx
|
|
|
|
}}
|
2017-02-11 13:28:45 +00:00
|
|
|
|
2016-08-13 12:49:04 +00:00
|
|
|
# extract the current file with the right command
|
2016-09-06 22:47:08 +00:00
|
|
|
# (xkcd link: https://xkcd.com/1168/)
|
2018-06-26 19:24:41 +00:00
|
|
|
cmd extract ${{
|
|
|
|
set -f
|
2017-09-07 20:01:57 +00:00
|
|
|
case $f in
|
|
|
|
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
|
|
|
*.tar.gz|*.tgz) tar xzvf $f;;
|
|
|
|
*.tar.xz|*.txz) tar xJvf $f;;
|
|
|
|
*.zip) unzip $f;;
|
|
|
|
*.rar) unrar x $f;;
|
|
|
|
*.7z) 7z x $f;;
|
2016-08-13 12:49:04 +00:00
|
|
|
esac
|
|
|
|
}}
|
|
|
|
|
2018-04-06 19:49:50 +00:00
|
|
|
# compress current file or selected files with tar and gunzip
|
2018-06-26 19:24:41 +00:00
|
|
|
cmd tar ${{
|
|
|
|
set -f
|
2017-09-07 20:01:57 +00:00
|
|
|
mkdir $1
|
2018-04-06 19:49:50 +00:00
|
|
|
cp -r $fx $1
|
|
|
|
tar czf $1.tar.gz $1
|
2017-09-07 20:01:57 +00:00
|
|
|
rm -rf $1
|
2016-08-13 12:49:04 +00:00
|
|
|
}}
|
2018-06-26 19:24:41 +00:00
|
|
|
|
|
|
|
# compress current file or selected files with zip
|
|
|
|
cmd zip ${{
|
|
|
|
set -f
|
|
|
|
mkdir $1
|
|
|
|
cp -r $fx $1
|
|
|
|
zip -r $1.zip $1
|
|
|
|
rm -rf $1
|
|
|
|
}}
|