BashRC: Improved the mpx command and aliases. VimRC: Corrected some broken command completions.

Signed-off-by: Hermann Mayer's avatarHermann Mayer <hermann.mayer92@gmail.com>
parent f9cb796d
67cf578d-a0ba-4bec-91c7-7e856bc0e9af
\ No newline at end of file
......@@ -428,8 +428,12 @@ if 1 == VimRCBundlesDevel
\ ['CANARY', 'PRODUCTION'],
\ ['blank?', 'present?'],
\ ['any?', 'all?', 'none?', 'one?'],
\ ['local', 'canary', 'production'],
\ ['local', 'development', 'test', 'canary', 'production'],
\ ['path', 'file'],
\ ['return', 'next'],
\ ['continue', 'break'],
\ ['are', 'is'],
\ ['include', 'exclude'],
\]
autocmd VimEnter * :IndentGuidesEnable
......
......@@ -109,7 +109,7 @@ function! s:CleanJade()
%s/- else/else/g
%s/- each/each/g
endfunction
command! -complete=shellcmd CleanJade call s:CleanJade()
command! -complete=shellcmd -nargs=? CleanJade call s:CleanJade()
command! Visual normal! v
command! VisualLine normal! V
......@@ -119,7 +119,7 @@ function s:OpenTerminal()
silent !clear
silent execute "!i3-sensible-terminal -cd " . getcwd() . " &"
endfunction
command! -complete=shellcmd OpenTerminal call s:OpenTerminal()
command! -complete=shellcmd -nargs=? OpenTerminal call s:OpenTerminal()
" Augmenting Ag command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
......
......@@ -208,6 +208,28 @@ function nobranch()
fi
}
function name()
{
if [ -z "$2" ]; then
mpx -s -X -d -n "${1}"
else
NAME="${1}"
shift
mpx -s -X -n "${NAME}" ${@}
fi
}
function noname()
{
if [ -z "$2" ]; then
mpx -s -X -d -N "${1}"
else
NAME="${1}"
shift
mpx -s -X -N "${NAME}" ${@}
fi
}
function dirty()
{
if [ -z "$1" ]; then
......@@ -250,6 +272,20 @@ function nobranch-edit()
nobranch "${BRANCH}" gvim -f ${@}
}
function name-edit()
{
NAME="${1}"
shift
name "${NAME}" gvim -f ${@}
}
function noname-edit()
{
NAME="${1}"
shift
noname "${NAME}" gvim -f ${@}
}
function mergepdfs()
{
local OUTPUT="merged.pdf"
......@@ -258,7 +294,9 @@ function mergepdfs()
OUTPUT="${1}"
fi
pdftk *.pdf cat output "${OUTPUT}"
pdftk \
$(find . -maxdepth 1 -type f -name '*.pdf' | sort -n) \
cat output "${OUTPUT}"
}
function cdtmp()
......
......@@ -27,6 +27,8 @@ def help(exit_code: nil)
is applied to the directory list. (-C no changes)
--[no]branch Only run the command when the Git branch (pattern) is
-b, -B present on each directory on the list.
--[no]name Only run the command when the directory name matches
-n, -N the given filter.
--[no]clear Soft reset the terminal after each command
-x, -X
--[no]reset, Hard reset the terminal after each command
......@@ -67,6 +69,17 @@ def skip_branch?(dir, branch)
end
end
def skip_name?(dir)
regex = $options[:name]
return false unless regex.is_a? Regexp
if $options[:name_skip]
dir.match?(regex)
else
!dir.match?(regex)
end
end
def skip_changes?(dir, branch)
# When no changes filter is set, do not skip
return false if $options[:changes].nil?
......@@ -137,7 +150,10 @@ def run(cur, all, dir)
end
branch = branch(dir)
skip = skip_branch?(dir, branch) || skip_changes?(dir, branch)
skip = skip_branch?(dir, branch) \
|| skip_changes?(dir, branch) \
|| skip_name?(dir)
header(cur, all, dir, skip, branch)
puts unless skip || $options[:dryrun]
......@@ -185,13 +201,21 @@ $options = {
dryrun: false,
compact: false,
branch: nil,
branch_skip: nil
branch_skip: nil,
name: nil,
name_skip: nil
}
unknown_opt = proc do
puts "Unknown option '#{str}'\n\n"
help(exit_code: 1)
end
# Analyse the given arguments
ARGV.each do |str|
# Detect options
if str.start_with?('-') && $endofargs == false
opt = true
case str
when /-h|--help/
help(exit_code: 0)
......@@ -217,11 +241,18 @@ ARGV.each do |str|
when /-B|--nobranch/
$options[:branch] = true
$options[:branch_skip] = true
when /-n|--name/
$options[:name] = true
$options[:name_skip] = false
when /-N|--noname/
$options[:name] = true
$options[:name_skip] = true
else
puts "Unknown option '#{str}'\n\n"
help(exit_code: 1)
unknown_opt.call if str.start_with? '--'
unknown_opt.call if str.split('-').last.length == 1
opt = false
end
next
next if opt
end
if File.directory? str
......@@ -229,8 +260,11 @@ ARGV.each do |str|
$dirs << str
$endofargs = true
else
if $options[:branch] == true
$options[:branch] = Regexp.new(str)
elsif $options[:name] == true
$options[:name] = Regexp.new(str)
else
# Must be part of the command
$command << str
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment