Skip to content

Commit

Permalink
added custom vim fzf function to view file version on other commits
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Apr 18, 2023
1 parent 7d9e146 commit 47dcf5f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .bash/fzf-git.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ glfa() {
--date-order --color=always $* \
| fzf --preview="$cmd" --ansi --no-sort --no-multi --reverse \
--tiebreak=index \
--no-info \
--min-height 20 \
--bind="enter:execute($cmd | LESS='-r' less)"
}
Expand All @@ -35,6 +36,7 @@ gbf() {
--preview="echo {} |grep -Eo '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]'|xargs -n1 git diff | delta" \
--ansi --no-multi --reverse \
--tiebreak=index \
--no-info \
--height 50% --min-height 20 \
| grep -Po '(?<=^. )[^ ]+ ' | xargs -n1 git switch
}
Expand All @@ -54,6 +56,7 @@ gaf() {

$cmd \
| fzf -m --header "$header" \
--no-info \
--reverse -0 -m --nth 2..,.. --ansi \
--height 50% --min-height 20 \
--expect="$_commit_key" \
Expand Down
1 change: 0 additions & 1 deletion .tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'MunifTanjim/tmux-suspend'
# set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'Morantron/tmux-fingers'
set -g @plugin 'laktak/extrakto'

set -g @plugin '3ximus/tmux-plugin-uptime'
set -g @plugin '3ximus/tmux-plugin-datetime'
Expand Down
54 changes: 35 additions & 19 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -764,33 +764,22 @@ if &rtp =~ 'fzf.vim' && glob("~/.vim/plugged/fzf.vim/plugin/fzf.vim")!=#""
let g:fzf_command_prefix = 'FZF'

if exists('$TMUX')
let g:fzf_layout = { 'tmux': '-p90%,60%' }
let g:fzf_layout = { 'tmux': '-p90%,70%' }
else
" let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.8 , 'border': 'sharp'} } " Causes airline gruvbox bug
let g:fzf_no_term = 1
let g:fzf_layout = { 'down': '30%' }
endif

" autocmd! FileType fzf
" autocmd FileType fzf set laststatus=0 noshowmode noruler
" \| autocmd BufLeave <buffer> set laststatus=2 showmode ruler

let g:fzf_history_dir = '~/.local/share/fzf-history'

" function to make quick fiz with selected results
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction

" Function to checkout a branch with FZF
function! GitCheckoutBranch(branch)
" branch can look like this: "/remotes/origin/master [hash] info" or this: "master [hash] info"
let l:name = split(split(trim(a:branch), "", 1)[0], "/", 1)[-1]
execute "Git checkout ".l:name
endfunction
command! -bang FZFGbranch call fzf#run({'source': 'git branch -avv --color', 'sink': function('GitCheckoutBranch'), 'options': '--ansi --nth=1', 'tmux': '-p60%,40%'})
command! -bang FZFGbranch call fzf#run({'source': 'git branch -avv --color', 'sink': function('GitCheckoutBranch'), 'options': '--prompt "Branch> " --ansi --nth=1', 'tmux': '-p60%,40%'})

" Function to checkout a file from another branch with FZF
function! GitEditBranchFile(branch)
Expand All @@ -805,10 +794,35 @@ if &rtp =~ 'fzf.vim' && glob("~/.vim/plugged/fzf.vim/plugin/fzf.vim")!=#""
execute "Gedit ".l:name.":%"
endif
endfunction
command! -bang FZFGeditFile call fzf#run({'source': 'git branch -avv --color', 'sink': function('GitEditBranchFile'), 'options': "'--bind=ctrl-v:execute@printf \">>>> \"@+accept' '--bind=ctrl-s:execute@printf \"&&&& \"@+accept' --ansi --nth=1", 'tmux': '-p60%,40%'})
command! -bang FZFGitEditBranchFile
\ call fzf#run({
\ 'source': 'git branch -avv --color',
\ 'sink': function('GitEditBranchFile'),
\ 'options': "'--bind=ctrl-v:execute@printf \">>>> \"@+accept' '--bind=ctrl-s:execute@printf \"&&&& \"@+accept' --prompt 'ViewCurrentFile> ' --ansi --nth=1 --no-info",
\ 'tmux': '-p60%,40%'})

function! GitEditCommitFile(commit)
let l:hash = substitute(a:commit, "^[^0-9a-zA-Z]\\+ \\([0-9a-zA-Z]\\+\\).*", "\\1", "")
" TODO preview here is not correct since it doesnt view the file content
" on the selected commit
let l:file = fzf#run(fzf#wrap({'source': 'git ls-tree --name-only -r ' . l:hash,
\ 'options': "--prompt --ansi --reverse --nth=1 --prompt 'ViewFile @ ".l:hash."> ' --inline-info --preview '~/.vim/plugged/fzf.vim/bin/preview.sh {}' '--bind=ctrl-v:execute@printf \">>>> \"@+accept' '--bind=ctrl-s:execute@printf \"&&&& \"@+accept'",
\ 'tmux': '-p80%,70%'}))
if len(l:file) == 0
return
endif
if match(l:file[0], '&&&& ') == 0
execute "Gsplit ".l:hash.":".split(l:file[0], "", 1)[1]
elseif match(l:file[0], '>>>> ') == 0
execute "Gvsplit ".l:hash.":".split(l:file[0], "", 1)[1]
else
execute "Gedit ".l:hash.":".l:file[0]
endif
endfunction
" TODO bind keys here so that by default it would do this action on the current file instead of opening files from the git repo
command! -bang FZFGitEditCommitFile call fzf#run({'source': 'git lol', 'sink': function('GitEditCommitFile'), 'options': "--prompt 'ViewFile> ' --ansi --reverse --nth=1 --no-info", 'tmux': '-p80%,70%'})

let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
Expand All @@ -830,15 +844,17 @@ if &rtp =~ 'fzf.vim' && glob("~/.vim/plugged/fzf.vim/plugin/fzf.vim")!=#""
nmap <leader>b :FZFBuffers<CR>
nmap <leader>l :FZFLines<CR>
nmap <leader>f :FZFRg<CR>
nmap <leader>F :FZFRgWithFilenames<CR>
nmap <leader>F :FZFRgWithFilenames<space>
nmap <leader>/ :FZFHistory/<CR>
nmap <leader>: :FZFHistory:<CR>
nmap <leader>m :FZFMaps:<CR>
noremap <leader>gv :FZFGeditFile<CR>
noremap <leader>gv :FZFGitEditBranchFile<CR>
noremap <leader>gV :FZFGitEditCommitFile<CR>
noremap <leader>gb :FZFGbranch<CR>
noremap <leader>gc :FZFCommits<CR>
vmap <leader>gc :FZFBCommits<CR>
noremap <leader>gC :FZFCommits --pretty=format:'\%C(yellow)\%h\%Creset \%C(auto)\%d\%Creset \%s (\%Cblue\%an\%Creset, \%cr)'<CR>
noremap <leader>gc :FZFBCommits --pretty=format:'%C(yellow)%h%Creset %C(auto)%d%Creset %s (%Cblue%an%Creset, %cr)'<CR>
vmap <leader>gc :FZFBCommits --pretty=format:'%C(yellow)%h%Creset %C(auto)%d%Creset %s (%Cblue%an%Creset, %cr)'<CR>
endif
" }}}

Expand Down
64 changes: 8 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ If new submodules where added you might need to run `git submodule init` again

To copy/link the files you want run `install_my_config.sh --help` to check the usage of this script

#### Vim

To install all the vim plugins open vim and run `:PluginInstall`

#### Tmux

To install the tmux plugins press `<prefix>+I` (it will freeze for a few seconds...)

## Prompts

### Current prompt:
Expand All @@ -94,63 +86,22 @@ z,s
- show the respective tty. **except 6, 7**
- display virtual machine environment indicator **only prompt 7**


## Vim

Vim configuration is huge but it's organized and documented, so just open the `.vimrc` file and check it out

### Plugin list (using [vim-plug](https://github.com/junegunn/vim-plug)):

It might have changed, so just check the `.vimrc` on the `VIM PLUG PLUGINS` section

- [vim-airline](https://github.com/vim-airline/vim-airline)
- [nerdtree](https://github.com/scrooloose/nerdtree)
- [nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin)

### Git
- [vim-gitgutter](https://github.com/airblade/vim-gitgutter)
- [vim-fugitive](https://github.com/tpope/vim-fugitive)
- [vim-rhubarb](https://github.com/tpope/vim-rhubarb)

### Tools
- [vim-surround](https://github.com/tpope/vim-surround)
- [vim-commentary](https://github.com/tpope/vim-commentary)
- [gundo.vim](https://github.com/sjl/gundo.vim)
- [vim-easymotion](https://github.com/easymotion/vim-easymotion)
- [quick-scope](https://github.com/unblevable/quick-scope)
- [linediff.vim](https://github.com/AndrewRadev/linediff.vim)
- [vim-peekaboo](https://github.com/junegunn/vim-peekaboo)
- [ctrlp.vim](https://github.com/ctrlpvim/ctrlp.vim)
- [vim-markology](https://github.com/jeetsukumaran/vim-markology)

### Tmux integration
- [vim-tmux-focus-events](https://github.com/tmux-plugins/vim-tmux-focus-events)
- [vim-tmux-clipboard](https://github.com/roxma/vim-tmux-clipboard)
- [vimux](https://github.com/preservim/vimux)

### Syntax highlight
- [vim-syntax-extra](https://github.com/justinmk/vim-syntax-extra)
- [vim-ps1](https://github.com/PProvost/vim-ps1)
- [python-syntax](https://github.com/vim-python/python-syntax)

### Extra
- [emmet-vim](https://github.com/mattn/emmet-vim)
To install all the vim plugins open vim and run `:PluginInstall`

### Colors
- [gruvbox](https://github.com/morhetz/gruvbox)
Vim configuration is huge but it's organized and documented, so just open the `.vimrc` file and check it out

### Others
- [vim-startify](https://github.com/mhinz/vim-startify)
- [vim-numbertoggle](https://github.com/jeffkreeftmeijer/vim-numbertoggle)
- [vim-auto-origami](https://github.com/benknoble/vim-auto-origami)
- [vim-startuptime](https://github.com/dstein64/vim-startuptime)
- [vim-devicons](https://github.com/ryanoasis/vim-devicons)
### Plugins (using [vim-plug](https://github.com/junegunn/vim-plug)):

## Vim (gruvbox theme) screenshots
Check the `.vimrc` on the `VIM PLUG PLUGINS` section for the list of plugins

![7](screenshots/vim.png)

## Tmux

To install the tmux plugins press `<prefix>+I` (it will freeze for a few seconds...)

![8](screenshots/tmux.png)

Tmux has a lot of custom configurations added in `.tmux.conf` and a few plugins inside `.tmux` added as submodules that are managed through [TPM (Tmux Plugin Manager)](https://github.com/tmux-plugins/tpm)
Expand All @@ -160,6 +111,7 @@ Tmux has a lot of custom configurations added in `.tmux.conf` and a few plugins
- [tmux-battery](https://github.com/tmux-plugins/tmux-battery)
- [tmux-plugin-uptime](https://github.com/3ximus/tmux-plugin-uptime)
- [tmux-plugin-datetime](https://github.com/3ximus/tmux-plugin-datetime)
- [tmux-suspend](https://github.com/MunifTanjim/tmux-suspend)

## Firefox
![10](screenshots/firefox.png)
Expand Down

0 comments on commit 47dcf5f

Please sign in to comment.