VimRC: Added a ruby-bundler package. BashRC: Added more fonts, updated some…

VimRC: Added a ruby-bundler package. BashRC: Added more fonts, updated some tooling and replaced the mpx implementation.
Signed-off-by: Hermann Mayer's avatarHermann Mayer <hermann.mayer92@gmail.com>
parent e9202c19
#!/usr/bin/env ruby
# vim: ft=ruby
$clr_rst = "\e[0m"
$clr_ylw = "\e[0;33m"
$clr_cyn = "\e[0;36m"
$clr_red = "\e[0;31m"
$clr_grn = "\e[0;32m"
$clr_mag = "\e[0;35m"
$term_cols = `tput cols`.to_i
def help(exit_code: nil)
puts <<~EOF
#{$PROGRAM_NAME} [OPTIONS] [DIR..] [COMMAND]
MultiPleXing - execute the given command on all given directories.
With this tool you can ease the work of repetetive tasks.
By default all directories in the current working directory are used
when the directory list is omitted by the user. The default command is
`ls -lisa` when no command is passed by the user.
Options
--[no]changes Only run the command when Git changes are present,
-c, -C or when Git changes are absent. By default no filter
is applied to the directory list. (-C no changes)
--[no]clear Soft reset the terminal after each command
-x, -X
--[no]reset, Hard reset the terminal after each command
-r, -R
--prompt, -p Prompt the user after each command
--dryrun, -d No actual command is invoked
--compact, -s No fancy headers
Examples
Show the Git status of all sub-directories of your CWD
$ mpx * "git status"
Push only the sub-directories with changes
$ mpx --changes "git push"
EOF
unless exit_code.nil?
exit(exit_code)
end
end
def branch(dir)
return nil unless File.directory? "#{dir}/.git"
output = `cd "#{dir}" && git rev-parse --abbrev-ref HEAD 2>&1`.strip
return nil if /fatal:/.match? output
output
end
def skip?(dir, branch)
# When no changes filter is set, do not skip
return false if $options[:changes].nil?
# Check for git changes
unless $options[:changes].nil?
changes = Dir.chdir(dir) do
# Check for uncommited file changes
output = `LC_ALL=C git status 2>&1`
changes = /Changes|Untracked files/.match? output
# Check for commits which are not yet pushed,
# in case there are no uncommited file changes
if !changes && branch
output = `LC_ALL=C git log origin/#{branch}..#{branch} 2>&1`
changes = output.lines.count > 0
end
changes
end
return false if changes && $options[:changes]
return false if !changes && !$options[:changes]
return true
end
false
end
def header(cur, all, dir, skip, branch)
line = ["#{$clr_ylw}##{$clr_rst}"]
line << sprintf('%3i/%i | %5.1f%%', cur, all, (cur * 1.0 / all) * 100) \
if $options[:prompt]
line << "#{$clr_red} [SKIP]" if skip
line << "#{$clr_grn} [CHANGES]" if $options[:changes] && !skip
line << "#{$clr_grn}[NO CHANGES]" \
if !$options[:changes] && !skip && !$options[:changes].nil?
line << "#{$clr_cyn}#{dir}"
line << "#{$clr_mag}(#{branch})#{$clr_rst}" unless branch.nil?
line = line.join(' ')
if $options[:compact]
puts line
else
no_color = line.gsub(/\e\[[^m]+m/, '').strip
len = no_color.length
add = $term_cols - len - 1
line << "#{' ' * add}#{$clr_ylw}#" if add > 1
line << "#{$clr_rst}"
puts "#{$clr_ylw}##{$clr_rst}" * $term_cols
puts line
puts "#{$clr_ylw}##{$clr_rst}" * $term_cols
puts "#{$clr_ylw}##{$clr_rst} Command: #{$command}" unless $options[:dryrun]
end
end
def run(cur, all, dir)
# Clear the terminal when configured
unless $options[:reset].nil?
system('clear') if $options[:reset] == :soft
system('reset') if $options[:reset] == :hard
end
branch = branch(dir)
skip = skip?(dir, branch)
header(cur, all, dir, skip, branch)
puts unless skip || $options[:dryrun]
# Run the command in case we should not skip the current directory
unless $options[:dryrun]
Dir.chdir(dir) do
system '/bin/bash', '-c', '/bin/bash ' \
'--rcfile <(echo "clear() { true; }; ' \
'trap \"exit\" EXIT; ' \
'trap() { true; }; ' \
'source ~/.bashrc 1>/dev/null 2>&1") ' \
"-ci #{$command.inspect}"
puts
end unless skip
end
# Prompt the user when configured
if $options[:prompt] && !skip
printf "\n#{$clr_ylw}##{$clr_rst} Press "
printf "#{$clr_ylw}[Enter]#{$clr_rst} to continue "
printf "or #{$clr_ylw}[Ctrl+C]#{$clr_rst} to abort"
begin
$stdin.gets
rescue SystemExit, Interrupt
puts "\n\nAborted."
exit(1)
end
end
puts unless $options[:compact]
end
$endofargs = false
$dirs = []
$command = []
$options = {
prompt: false,
reset: nil,
changes: nil,
dryrun: false,
compact: false
}
# Analyse the given arguments
ARGV.each do |str|
# Detect options
if str.start_with?('-') && $endofargs == false
case str
when /-h|--help/
help(exit_code: 0)
when /-C|--nochanges/
$options[:changes] = false
when /-c|--changes/
$options[:changes] = true
when /-x|--clear/
$options[:reset] = :soft
when /-r|--reset/
$options[:reset] = :hard
when /-X|--noclear|-R|--noreset/
$options[:reset] = nil
when /-p|--prompt/
$options[:prompt] = true
when /-d|--dryrun/
$options[:dryrun] = true
when /-s|--compact/
$options[:compact] = true
else
puts "Unknown option '#{str}'\n\n"
help(exit_code: 1)
end
next
end
if File.directory? str
# Detect directories
$dirs << str
$endofargs = true
else
# Must be part of the command
$command << str
$endofargs = true
end
end
# Set defaults
#
# Use all directories in our CWD when no dirs were passed
$dirs = Dir.glob('*').select { |file| File.directory? file } \
if $dirs.empty?
# Use a default command when no command was passed
$command = %w(ls -lisa) if $command.empty?
$command = $command.join(' ')
# If no arguments were given, just list dirs with changes
if ARGV.empty?
$options[:reset] = nil
$options[:changes] = true
$options[:compact] = true
$options[:dryrun] = true
end
# Run the configured command on all configured directories
$dirs.sort.each_with_index { |dir, idx| run(idx + 1, $dirs.count, dir) }
install: --no-ri --no-rdoc
update: --no-ri --no-rdoc
install: --no-document
update: --no-document
fb86c0f1-3fd8-4677-aba4-a75f7eae8259
\ No newline at end of file
24699ffe-94e4-4e38-81c4-144689074b51
\ No newline at end of file
......@@ -44,17 +44,20 @@ if 1 == VimRCBundlesMisc
" 1 = show scope in abbreviation and remove the last column
let OmniCpp_ShowScopeInAbbr = 0
" This option allows to display the prototype of a function in the abbreviation part of the popup menu.
" This option allows to display the prototype of a function in the
" abbreviation part of the popup menu.
" 0 = don't display prototype in abbreviation
" 1 = display prototype in abbreviation
let OmniCpp_ShowPrototypeInAbbr = 1
" This option allows to show/hide the access information ('+', '#', '-') in the popup menu.
" This option allows to show/hide the access information ('+', '#', '-') in
" the popup menu.
" 0 = hide access
" 1 = show access
let OmniCpp_ShowAccess = 1
" This option can be use if you don't want to parse using namespace declarations in included files and want to add
" This option can be use if you don't want to parse using namespace
" declarations in included files and want to add
" namespaces that are always used in your project.
let OmniCpp_DefaultNamespaces = ["std"]
......@@ -63,13 +66,14 @@ if 1 == VimRCBundlesMisc
let OmniCpp_MayCompleteArrow = 0
let OmniCpp_MayCompleteScope = 0
" When 'completeopt' does not contain "longest", Vim automatically select the first entry of the popup menu. You can
" When 'completeopt' does not contain "longest", Vim automatically select
" the first entry of the popup menu. You can
" change this behaviour with the OmniCpp_SelectFirstItem option.
let OmniCpp_SelectFirstItem = 0
" Configure the tcommenter
call tcomment#DefineType('c', '// %s')
call tcomment#DefineType('java', '// %s')
call tcomment#type#Define('c', '// %s')
call tcomment#type#Define('java', '// %s')
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
......@@ -103,7 +107,9 @@ if 1 == VimRCBundlesMisc
inoremap <expr><C-l> neocomplcache#complete_common_string()
" SuperTab like snippets behavior.
" imap <expr><TAB> neocomplcache#sources#snippets_complete#expandable() ? "\<Plug>(neocomplcache_snippets_expand)" : pumvisible() ? "\<C-n>" : "\<TAB>"
" imap <expr><TAB> neocomplcache#sources#snippets_complete#expandable() ?
" "\<Plug>(neocomplcache_snippets_expand)" : pumvisible() ? "\<C-n>" :
" "\<TAB>"
" Recommended key-mappings.
" <CR>: close popup and save indent.
......@@ -196,7 +202,7 @@ if 1 == VimRCBundlesMisc
let g:indent_guides_start_level = 2
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_exclude_filetypes = ['help', 'nerdtree']
let g:nerdtree_open_cmd = 'setsid xdg-open'
" +-----------------------------------------------
" | delimitMate
......@@ -220,7 +226,8 @@ if 1 == VimRCBundlesDevel
" +-----------------------------------------------
" Start Tagbar on known filetype and new buffers automatically
" autocmd BufEnter * nested if (!&readonly && &buftype != 'nofile' && &buftype != 'help') | :call tagbar#autoopen(1) | endif
" autocmd BufEnter * nested if (!&readonly && &buftype != 'nofile' &&
" &buftype != 'help') | :call tagbar#autoopen(1) | endif
" Start Tagbar only on listed filetypes
" autocmd FileType c,cpp,java,javascript,sh nested :TagbarOpen
......@@ -267,13 +274,17 @@ if 1 == VimRCBundlesDevel
" au BufAdd,BufNewFile * nested tab sball
" Auto close duplicated tabs
autocmd TabEnter * :CloseDupTabs
" autocmd WinEnter * autocmd TabEnter * :CloseDupTabs
" Auto focus buffer when switching tabs
autocmd TabEnter * :wincmd l
" Sets the working directory to the current file's directory
autocmd BufEnter * lcd %:p:h
" Close vim if the only window left open is a NERDTree
" autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&
" b:NERDTreeType == "primary") | q | endif
" User-defined surroundings
let g:surround_{char2nr('q')} = "'\r'" " q - like (q)uotes
......@@ -371,9 +382,12 @@ if 1 == VimRCBundlesDevel
\ ['absolute', 'relative', 'fixed', 'static'],
\ ['public', 'private'],
\ ['Public', 'Private'],
\ ['context', 'describe'],
\ ['context', 'describe', 'xcontext', 'xdescribe'],
\ ['it', 'xit'],
\ ['header', 'footer'],
\ ['Header', 'Footer'],
\ ['with', 'without'],
\ ['first', 'last'],
\]
autocmd VimEnter * :IndentGuidesEnable
......
......@@ -14,7 +14,7 @@ if 1 == VimRCBundlesMisc
" Gvim colorscheme
Plugin 'Wombat'
" Close duplicate tabs
Plugin 'close-duplicate-tabs'
Plugin 'sorribas/vim-close-duplicate-tabs'
" Camelcase motion
Plugin 'camelcasemotion'
" Better file browser
......@@ -97,6 +97,8 @@ if 1 == VimRCBundlesDevel
Plugin 'Matt-Deacalion/vim-systemd-syntax'
" A Vim plugin which shows a git diff in the 'gutter' (sign column)
Plugin 'airblade/vim-gitgutter'
" Elixir support for vim
Plugin 'elixir-editors/vim-elixir'
endif
if 1 == VimRCBundlesHTML
......@@ -171,6 +173,8 @@ if 1 == VimRCBundlesRuby
Plugin 'tpope/vim-rails'
" Ruby completions
Plugin 'vim-ruby/vim-ruby'
" Bundler support
Plugin 'tpope/vim-bundler'
endif
if 1 == VimRCBundlesSysAdmin
......
......@@ -135,3 +135,27 @@ command! -bang -nargs=* Ag
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Like tabdo but restore the current tab.
function! TabDo(command)
let currTab=tabpagenr()
execute 'tabdo ' . a:command
execute 'tabn ' . currTab
endfunction
com! -nargs=+ -complete=command Tabdo call TabDo(<q-args>)
" Run google.com/codesearch on the current word
function! OnlineDoc()
let s:wordUnderCursor = expand("<cword>")
let s:url = "http://www.google.com/search?q=" . &ft . " " . s:wordUnderCursor
silent execute "!setsid xdg-open '" . s:url . "'"
redraw!
endfunction
" Run dict.cc on the current word
function! OnlineDict()
let s:wordUnderCursor = expand("<cword>")
let s:url = "https://www.dict.cc/?s=".s:wordUnderCursor
silent execute "!setsid xdg-open '" . s:url . "'"
redraw!
endfunction
......@@ -199,6 +199,8 @@ cmap <C-y> <C-R>+
" Quick Save
map <C-s> <ESC>:w<CR>
imap <C-s> <ESC>:w<CR>i
map <C-d> <ESC>:Tabdo write<CR>
imap <C-d> <ESC>:Tabdo write<CR>i
" Add alternative number increment/decrement mapping
nnoremap <A-x> <C-a>
......@@ -255,7 +257,7 @@ nnoremap <C-LeftMouse> <LeftMouse>:tab split<CR>:exec("tag ".expand("<cword>"))<
" Remap keys to make it more similar to firefox tab functionality
map <C-T> <ESC>:tabnew<CR>
map <C-N> <ESC>:!gvim &<CR><CR>
map <C-W> <ESC>:confirm bdelete<CR>
" map <C-W> <ESC>:confirm bdelete<CR>
" Search and replace selection on Ctrl+r
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
......@@ -289,3 +291,7 @@ nnoremap <silent> <leader>DQ :exe ":profile pause"<cr>:noautocmd qall!<cr>
" Search with ag/fzf
map <Leader>s <ESC>:Ag<space>
map <Leader>ag <ESC>:Ag<space>
" Online doc search
nnoremap <Leader>k :call OnlineDoc()<CR>
nnoremap <Leader>ii :call OnlineDict()<CR>
......@@ -148,3 +148,13 @@ endif
" Change cursor shape in different modes - Konsole
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" Change the default split opening
set splitbelow
set splitright
" Allow many tabs on startup
set tabpagemax=100
" Allow netrw to open URLs under the cursor with a browser
let g:netrw_browsex_viewer= "setsid xdg-open"
......@@ -35,11 +35,11 @@ so ~/.bashrc.d/vim.conf
let iCanHazVundle=1
let vundle_readme=expand('~/.vim/bundle/Vundle.vim/README.md')
if !filereadable(vundle_readme)
echo "Installing Vundle..."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
let iCanHazVundle=0
echo "Installing Vundle..."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
let iCanHazVundle=0
endif
" Required for vundle
......@@ -54,7 +54,7 @@ Bundle 'VundleVim/Vundle.vim'
" Load user defined pre vim config
if filereadable(glob("~/.bashrc.d/vim.pre.conf"))
so ~/.bashrc.d/vim.pre.conf
so ~/.bashrc.d/vim.pre.conf
endif
......@@ -71,9 +71,9 @@ filetype plugin indent on
" Installing plugins the first time
if iCanHazVundle == 0
echo "Installing Bundles, please ignore key map error messages"
echo ""
:PluginInstall
echo "Installing Bundles, please ignore key map error messages"
echo ""
:PluginInstall
endif
......@@ -82,26 +82,26 @@ endif
" +-----------------------------------------------
if 1 == VimRCMisc
so ~/.vim/vimrc/misc.vim
so ~/.vim/vimrc/misc.vim
endif
if 1 == VimRCFiletypes
so ~/.vim/vimrc/filetypes.vim
so ~/.vim/vimrc/filetypes.vim
endif
if 1 == VimRCBundlesOptions
so ~/.vim/vimrc/bundles-options.vim
so ~/.vim/vimrc/bundles-options.vim
endif
if 1 == VimRCFunctions
so ~/.vim/vimrc/functions.vim
so ~/.vim/vimrc/functions.vim
endif
if 1 == VimRCKeymap
so ~/.vim/vimrc/keymap.vim
so ~/.vim/vimrc/keymap.vim
endif
" Load user defined post vim config
if filereadable(glob("~/.bashrc.d/vim.post.conf"))
so ~/.bashrc.d/vim.post.conf
so ~/.bashrc.d/vim.post.conf
endif
......@@ -27,4 +27,3 @@ alias mkdir='mkdir -p -v'
alias openports='netstat --all --numeric --programs --inet --inet6 | tail -n +3 | rev | sort -k 1,1 | rev'
alias less='less -R'
alias x='exit'
alias all='mpx *'
......@@ -9,15 +9,61 @@
function debughtml()
{
cat - | xmllint --format --html --recover - | highlight --out-format=xterm256 -S xml -- | less -R
cat - | xmllint --format --html --recover - \
| highlight --out-format=xterm256 -S xml -- \
| less -R
}
function debugxml()
{
cat - | xmllint --format --recover - | highlight --out-format=xterm256 -S xml -- | less -R
cat - | xmllint --format --recover - \
| highlight --out-format=xterm256 -S xml -- \
| less -R
}
function generateMAC()
{
echo $(dd bs=1 count=6 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"' | sed 's/^-//g')
echo $(dd bs=1 count=6 if=/dev/random 2>/dev/null \
| hexdump -v -e '/1 "-%02X"' | sed 's/^-//g')
}
function gemlock()
{
grep -P "^\s*${@} \(\d" Gemfile.lock \
| cut -d '(' -f2 \
| grep -oP '[^)]+'
}
function gemdesc()
{
curl -s "https://rubygems.org/gems/${@}" \
| pup -p '.gem__intro p text{}' \
| tr "\n" ' ' \
| sed 's/ */ /g' \
| fold -s -w78 - \
| sed 's/^/# /g' \
| sed 's/[ \t]*$//'
echo
}
function gemspec()
{
curl -s "https://rubygems.org/gems/${@}" \
| pup -p '#gemfile_text attr{value}'
}
function gemline()
{
SPEC="gem '${1}', '~> ${2}'"
if [ -z "${2}" ]; then
SPEC="$(gemspec ${@})"
fi
gemdesc ${1}
echo ${SPEC}
}
function gemlockline()
{
gemline "${@}" $(gemlock "${@}")
}
......@@ -99,7 +99,7 @@ function docker-user-container-here()
echo 'Additional environment variables:'
echo ' PORT Host port to open, default: random'
echo ' CONTAINER_PORT Container port, default: 3000'
exit 1
return 1
fi
if [ -z "${PORT}" ]; then
local PORT=$(shuf -i 26000-30000 -n 1)
......@@ -188,3 +188,8 @@ function docker-stop-all()
docker ps -aq | \
xargs -rn1 docker rm -f
}
function docker-shell()
{
docker-user-container-here $@
}
......@@ -65,7 +65,7 @@ function md2html()
echo > "${OUT}"
cat << 'EOF' > "${TOC}"
# Gliederung
# Table of contents
EOF
grep -P '^#' *.md | cut -d ':' -f2 | \
......@@ -89,7 +89,7 @@ EOF
process.stdin.on('end', function() {
var tmp = '# Gliederung\n\n';
var tmp = '# Table of contents\n\n';
chunks.split('\n').forEach(function(line) {
......@@ -124,10 +124,10 @@ EOF
cat << 'EOF' >> "${OUT}"
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400" rel="stylesheet" type="text/css">
<link href="http://cdn.hermann-mayer.net/styles/markdown.css" rel="stylesheet"></link>
<link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/github.min.css">
<script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<link href="https://s3-eu-west-1.amazonaws.com/jack12816/public/pastes/markdown.css" rel="stylesheet"></link>
<link rel="stylesheet" href="https://yandex.st/highlightjs/7.3/styles/github.min.css">
<script src="https://yandex.st/highlightjs/7.3/highlight.min.js"></script>
<script src="https://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<script>
hljs.tabReplace = ' ';
hljs.initHighlightingOnLoad();
......@@ -150,7 +150,7 @@ EOF
</head>
<body>
<div class="hidden-on-print" style="position: fixed; right: 20px; bottom: 20px;">
<a class="btn btn-primary" href="#Gliederung">Gliederung</a>
<a class="btn btn-primary" href="#Table of contents">Table of contents</a>
</div>
EOF
......@@ -240,43 +240,32 @@ function greview()
done
}
function mpx()
function dirty()
{
CWD="$(pwd)"
txtylw='\e[0;33m' # Yellow
txtcyn='\e[0;36m' # Cyan
txtrst='\e[0m' # Text Reset
paths="*/"
cmd="${@}"
if [ $# -gt 1 ]; then
paths=''
cmd="${@: -1}"
for path in "${@:1:$(($#-1))}"; do
paths=$(echo "${paths} ${path}")
done
if [ -z "$1" ]; then
mpx -s -X -c -d
else
mpx -s -X -c ${@}
fi
}
if [ '' = "${cmd}" ]; then
cmd='ls -lisa'
function nodirty()
{
if [ -z "$1" ]; then
mpx -s -X -C -d
else
mpx -s -X -C ${@}
fi
}
find ${paths} -maxdepth 0 | while read file; do
echo
echo
echo -e "${txtylw}##########################${txtrst}"
echo -e "${txtylw}## ${txtcyn}${file}${txtrst}"
echo -e "${txtylw}##########################${txtrst}"
echo -e "${txtrst}"
cd "${file}"
eval "${cmd}"
cd "${CWD}"
done
function dirty-edit()
{
dirty gvim -f ${@}
}
cd "${CWD}"
function nodirty-edit()
{
nodirty gvim -f ${@}
}
function mergepdfs()
......
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