BashRC: Added a new TERM_APP environment variable to detect the terminal host…

BashRC: Added a new TERM_APP environment variable to detect the terminal host app. Added a catnl helper for fast string embedding. VimRC: Added more swap words and a new Ruby tooling (:CA) which creates missing alternate files. Also the NERDTree plugin collection was increased and basic tooling for Github links was added. Last but not least the Vim performance (boot and runtime) was improved by not using a Bash login shell.
Signed-off-by: Hermann Mayer's avatarHermann Mayer <hermann.mayer92@gmail.com>
parent b95599d5
......@@ -32,6 +32,19 @@ __getBashRCSourceRoot
export BASHRC_VERSION=$(cd "$BASHRC_SOURCE_ROOT" && git log --pretty="%h" -n1 HEAD)
export PATH="$PATH:${BASHRC_SOURCE_ROOT}/../bin:${BASHRC_SOURCE_ROOT}/../vendors"
# Find the current bash process host process (eg. urxvt, gvim)
# term_pid=$$
# declare -a term_coms
# while true; do
# term_pid=$(ps -h -o ppid -p $term_pid 2>/dev/null)
# term_com=$(ps -h -o comm -p $term_pid 2>/dev/null)
# term_coms+=($term_com)
# test -z "${term_com}" && break
# test "${term_com}" = 'systemd' && break
# test "${term_com}" = 'clone-terminal' && break
# done
# export TERM_APP=${term_coms[-2]}
# +-------------------------------------------------
# | LDAP Config
# +-------------------------------------------------
......
24699ffe-94e4-4e38-81c4-144689074b51
\ No newline at end of file
#!/usr/bin/env ruby
require 'fileutils'
file = ARGV[0]
exit 1 unless File.exist? file
def project_root(file)
dir = File.dirname(file)
loop do
git = File.exist? File.join(dir, '.git')
readme = File.exist? File.join(dir, 'README.md')
return dir if git && readme
dir = File.expand_path(File.join(dir, '..'))
exit 1 if dir == '/'
end
end
def spec?(rel)
rel.match? %r{^(spec|test|tests)/}
end
def spec_dir(base)
return 'spec' if File.directory? File.join(base, 'spec')
return 'test' if File.directory? File.join(base, 'test')
return 'tests' if File.directory? File.join(base, 'tests')
'spec'
end
def app_dir(base)
return 'app' if File.directory? File.join(base, 'app')
return 'lib' if File.directory? File.join(base, 'lib')
return 'src' if File.directory? File.join(base, 'src')
'app'
end
def switch_base(rel, new_base)
parts = rel.split('/')
parts.shift
parts.unshift(new_base)
parts.join('/')
end
base = project_root(file)
rel = file.gsub(%r{^#{base}/}, '')
if spec? rel
rel = switch_base(rel, app_dir(base)).gsub(/_spec\.rb$/, '.rb')
else
rel = switch_base(rel, spec_dir(base)).gsub(/\.rb$/, '_spec.rb')
end
abs = File.join(base, rel)
exit if File.exist? abs
FileUtils.mkdir_p(File.dirname(abs))
File.write(abs, <<~EOF
# frozen_string_literal: true
EOF
)
puts abs
......@@ -203,6 +203,7 @@ if 1 == VimRCBundlesMisc
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'
let g:nerdtree_plugin_open_cmd = 'setsid xdg-open'
" +-----------------------------------------------
" | delimitMate
......@@ -394,6 +395,14 @@ if 1 == VimRCBundlesDevel
\ ['Header', 'Footer'],
\ ['with', 'without'],
\ ['first', 'last'],
\ ['Given', 'When', 'Then', 'And'],
\ ['before', 'after'],
\ ['allow', 'expect'],
\ ['failed', 'succeeded'],
\ ['included', 'class_methods'],
\ ['requires', 'optional'],
\ ['same', 'different'],
\ ['when', 'with', 'without'],
\]
autocmd VimEnter * :IndentGuidesEnable
......
......@@ -25,6 +25,12 @@ if 1 == VimRCBundlesMisc
Plugin 'nelstrom/vim-textobj-rubyblock'
" Better file browser
Plugin 'scrooloose/nerdtree'
" NERDTree with tabs
Plugin 'jistr/vim-nerdtree-tabs'
" NERDTree with chmod support
Plugin 'EvanDotPro/nerdtree-chmod'
" Ability to open non text files with an appropriate application
Plugin 'woelke/vim-nerdtree_plugin_open'
" Tab list panel
" Plugin 'kien/tabman.vim'
" Powerline
......@@ -40,8 +46,6 @@ if 1 == VimRCBundlesMisc
Plugin 'tomtom/tlib_vim'
" Dependency of vim-twig and many other bundles
Plugin 'MarcWeber/vim-addon-mw-utils'
" NERDTree with tabs
Plugin 'jistr/vim-nerdtree-tabs'
" Interactive way to use motions
Plugin 'Lokaltog/vim-easymotion'
" Show indent level
......@@ -71,6 +75,8 @@ if 1 == VimRCBundlesMisc
" Increasing and decreasing number or letter sequences
" on multiple lines via visual mode
Plugin 'triglav/vim-visual-increment'
" Advanced URI/Browser handling instead of a broken netrw/gx
Plugin 'tyru/open-browser.vim'
endif
if 1 == VimRCBundlesDevel
......
......@@ -159,3 +159,25 @@ function! OnlineDict()
silent execute "!setsid xdg-open '" . s:url . "'"
redraw!
endfunction
" Convert the current file to a Github link and open it
function! GithubLink()
let s:url = substitute(trim(system("gh-link " . expand('%:p') . " L" . line("."))), "#", "\\\\#", "")
silent execute "!setsid xdg-open '" . s:url . "' >/dev/null 2>&1"
redraw!
endfunction
" Create the alternative ruby file if it does not yet exists
function! s:CreateAlternative()
let cmd = "~/.vim/tools/create-alternate.rb '" . expand('%:p') . "'"
let new_path = system(cmd)
if new_path != ''
echo new_path
execute 'tabnew' new_path
redraw!
execute ':AR'
call append(line('1'), ['# frozen_string_literal: true', ''])
execut ':w'
endif
endfunction
command! CA exe s:CreateAlternative()
......@@ -302,3 +302,17 @@ nnoremap <Leader>ii :call OnlineDict()<CR>
" A remapping of the vim-visual-increment plugin
vmap <C-I> <Plug>VisualIncrement
vmap <C-A-I> <Plug>VisualDecrement
" A Github link opener
noremap <Leader>g :call GithubLink()<CR>
" Open URI under cursor
nmap gx <Plug>(openbrowser-open)
" Open selected URI
vmap gx <Plug>(openbrowser-open)
" Search word under cursor
nmap gs <Plug>(openbrowser-search)
" Search selected word
vmap gs <Plug>(openbrowser-search)
" Create an alternative file on a Ruby project
......@@ -3,7 +3,7 @@
" +-----------------------------------------------
" use bash login-shell for a proper environment
set shell=bash\ -l
" set shell=/bin/bash\ -l
let $PATH=system('echo $PATH')
" allow plugins by file type
......@@ -158,6 +158,8 @@ set tabpagemax=100
" Allow netrw to open URLs under the cursor with a browser
let g:netrw_browsex_viewer= "setsid xdg-open"
let g:netrw_http_cmd = "setsid xdg-open"
let g:netrw_nogx = 1
" Allow to keep the indent when line formatting (gq)
set breakindent
......
......@@ -275,3 +275,8 @@ function cdtmp()
mkdir "/tmp/${name}"
cd "/tmp/${name}"
}
function catnl()
{
cat $@ | sed ':a;N;$!ba;s/\n/\\n/g'
}
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