<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Zanets</title>
    <description>The latest articles on Forem by Zanets (@zanets).</description>
    <link>https://forem.com/zanets</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F403240%2F8abd36d9-6295-45b8-909d-7dac2e59aa79.png</url>
      <title>Forem: Zanets</title>
      <link>https://forem.com/zanets</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zanets"/>
    <language>en</language>
    <item>
      <title>How to find the commits from last pull</title>
      <dc:creator>Zanets</dc:creator>
      <pubDate>Sun, 07 Jun 2020 02:26:07 +0000</pubDate>
      <link>https://forem.com/zanets/how-to-know-the-commits-from-last-pull-197h</link>
      <guid>https://forem.com/zanets/how-to-know-the-commits-from-last-pull-197h</guid>
      <description>&lt;p&gt;I came out with this question recently: how to find those commits from last &lt;code&gt;git pull&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Of course you can check &lt;code&gt;git log&lt;/code&gt; first, record the last commit and check again after &lt;code&gt;git pull&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Obviously not an ideal approach for a lazy developer like me.&lt;/p&gt;

&lt;p&gt;Here is an example. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzfp2svtulydza1o3czc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzfp2svtulydza1o3czc6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, this local repository is on &lt;code&gt;ed102ca&lt;/code&gt;, but remote is on &lt;code&gt;7b44e48&lt;/code&gt;. &lt;br&gt;
So, how do I find those commits from &lt;code&gt;3dea674&lt;/code&gt; to &lt;code&gt;7b44e48&lt;/code&gt; after &lt;code&gt;git pull&lt;/code&gt; ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;git reflog + git show&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What is reflog ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, it's a log which records the modified when &lt;code&gt;HEAD&lt;/code&gt; is changed. Such as &lt;code&gt;git rebase&lt;/code&gt;, &lt;code&gt;git commit&lt;/code&gt; and &lt;code&gt;git pull&lt;/code&gt; will change the &lt;code&gt;HEAD&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After you did a &lt;code&gt;git pull&lt;/code&gt;, your last &lt;code&gt;reflog&lt;/code&gt; will like this.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

7b44e48 HEAD@{0}: pull: Fast-forward
952bd4d HEAD@{1}: ...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can use &lt;code&gt;git show&lt;/code&gt; to see the difference between &lt;code&gt;HEAD@{1}&lt;/code&gt; and &lt;code&gt;HEAD@{0}&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

git show @@{1}..@@{0}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;@@{n}&lt;/code&gt; is an alias of &lt;code&gt;HEAD@{n}&lt;/code&gt;, so this command shows the diff between &lt;code&gt;HEAD@{1}&lt;/code&gt; and &lt;code&gt;HEAD@{0}&lt;/code&gt; which contains commits from &lt;code&gt;3dea674&lt;/code&gt; to &lt;code&gt;7b44e48&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git show&lt;/code&gt; shows commit message and file diff in pager by default, use this command instead when you just want an overview list.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

git -c pager.show=false show --format="%h %an %s" -q @@{1}..@@{0}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This command shows commit hash, author and subject, without diff result and doesn't use pager.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ git -c pager.show=false show --format="%h %an %s" -q @@{1}..@@{0}
7b44e48 Zanets [refactor][git] don't need bash
f322bee Zanets [feat][vim/fzf] enhance color
c30740f Zanets [feat][bash] ls colors
4985b83 Zanets [feat][bash] get support multiple url
952bd4d Zanets [feat][tmux] better output color
7239d0f Zanets [feat][vim] enhance Help
650ed49 Zanets [refactor][vim] use a/b/c/d
1e092fd Zanets [refactor][vim] move comment to backup
3dea674 Zanets [config][vim] use origin fzf.vim
$


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Which is exactly what I want.&lt;/p&gt;

&lt;h2&gt;
  
  
  more
&lt;/h2&gt;

&lt;p&gt;Sometimes &lt;code&gt;@@{1}..@@{0}&lt;/code&gt; shows nothing, it's usually because of rebase&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

7b44e48 HEAD@{0}: rebase finished: returning to refs/heads/master
7b44e48 HEAD@{1}: pull: checkout 7b44e48646057a89e8f90ff6953b2c696d06eeda
ed102ca HEAD@{2}: ...


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If this happen, use &lt;code&gt;@@{2}..@@{0}&lt;/code&gt; instead.&lt;/p&gt;

</description>
      <category>git</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Custom git command</title>
      <dc:creator>Zanets</dc:creator>
      <pubDate>Sat, 06 Jun 2020 17:28:26 +0000</pubDate>
      <link>https://forem.com/zanets/custom-git-command-24lm</link>
      <guid>https://forem.com/zanets/custom-git-command-24lm</guid>
      <description>&lt;p&gt;There is an 'alias' section in gitconfig to create custom command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[alias]
    ck = checkout
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can type &lt;code&gt;git ck&lt;/code&gt; instead of &lt;code&gt;git checkout&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But the most powerful of alias is it also accept shell script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test = "! echo git-test"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can have a lot of fun.&lt;br&gt;
You can just write a tiny script in gitconfig like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test = "! \
    f() { \
        echo git-test-start; \
        echo $1; \
        echo git-test-end; \
    }; f"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Bascally I create a function and call it immediatly. Wrap in a function so that we can use &lt;code&gt;$@, $1...&lt;/code&gt; to access arguments.&lt;/p&gt;

&lt;p&gt;But since alias needs to be a single line, you need &lt;code&gt;; \&lt;/code&gt; at each end of line. It's fine for simple script but painful for complex one. So I came out with another approach&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test = "! ~/bin/git.sh do_test"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And create &lt;code&gt;~/bin/git.sh&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env bash

do_test() {
    echo git-test-start
    echo $1
    echo git-test-end
}

"$@"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then don't forget &lt;code&gt;chmod +x ~/bin/git.sh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That's it. It's very useful for those complex and hard to remember tricks of git.&lt;/p&gt;

</description>
      <category>git</category>
      <category>bash</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Fancy fzf on neovim</title>
      <dc:creator>Zanets</dc:creator>
      <pubDate>Sat, 06 Jun 2020 16:29:27 +0000</pubDate>
      <link>https://forem.com/zanets/fancy-fzf-on-neovim-41m8</link>
      <guid>https://forem.com/zanets/fancy-fzf-on-neovim-41m8</guid>
      <description>&lt;p&gt;After neovim 4.0 and vim 8.1, both of them have an amazing feature: popup window.&lt;br&gt;
That's take a look how it makes fzf better.&lt;/p&gt;

&lt;p&gt;This is how fzf looks in terminal buffer.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh82wwucko0rye0nol386.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh82wwucko0rye0nol386.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how fzf looks in popup window.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F305xh1swntm2ck39ozng.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F305xh1swntm2ck39ozng.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two reason why I prefer popup window.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The position of cursor doesn't move.&lt;/li&gt;
&lt;li&gt;Looks more like a "menu".&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Configure fzf to use popup window
&lt;/h2&gt;

&lt;p&gt;Thanks to the author of fzf, fzf has supported the popup window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.5, 'highlight': 'Comment' } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the window entry is a dictionary, fzf will treat the value as the attribute of popup window. Here are some attributes you can set&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;width: float range [0 ~ 1]
&lt;/li&gt;
&lt;li&gt;height: float range [0 ~ 1]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Optional&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;yoffset: float default 0.5 range [0 ~ 1]
&lt;/li&gt;
&lt;li&gt;xoffset: float default 0.5 range [0 ~ 1]
&lt;/li&gt;
&lt;li&gt;highlight: [string]: Highlight group for border
&lt;/li&gt;
&lt;li&gt;border: [string default rounded]: Border style&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avaliable Border Style: rounded: / sharp / horizontal / vertical / top / bottom / left / right &lt;/p&gt;

&lt;h2&gt;
  
  
  Customize the colors
&lt;/h2&gt;

&lt;p&gt;If you have set colors in FZF_DEFAULT_OPTS, then you don't have to worry this. If not, you can set in shell or neovim.&lt;/p&gt;

&lt;p&gt;You can find those elements which can be customized here: &lt;a href="https://github.com/junegunn/fzf/blob/a9fba1c8496f7352de55b9fe5f36f23872e5a364/README-VIM.md#L140" rel="noopener noreferrer"&gt;https://github.com/junegunn/fzf/blob/a9fba1c8496f7352de55b9fe5f36f23872e5a364/README-VIM.md#L140&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;shell&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export FZF_DEFAULT_OPTS='
    --color fg:14,fg+:3,hl:5,hl+:5,bg:-1,bg+:-1
    --color info:6,prompt:6,spinner:1,pointer:3
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, yes, pass two '--color' to fzf is legal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;neovim&lt;/strong&gt;&lt;br&gt;
It's a little harder than in shell. You need to set &lt;code&gt;g:fzf_colors&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let g:fzf_colors =
  \ { 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'] }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Uh...what are them ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'bg+':     ['bg', 'CursorLine', 'CursorColumn']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The logic is &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FZF will color 'bg+' with the 'bg' of highlight group 'CursorLine'. &lt;/li&gt;
&lt;li&gt;If 'CursorLine' doesn't have 'bg', then find in  'CursorColumn' and so on. &lt;/li&gt;
&lt;li&gt;If none of them have 'bg', use default value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you don't like to use an unrelated highlight group like me, you can create new ones for fzf.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hi! fzf_fg ctermfg=14                                                                                                                                                       
hi! fzf_fgp ctermfg=3                                                                                                                                                       
hi! fzf_hl ctermfg=5                                                                                                                                                        
hi! fzf_hlp ctermfg=5                                                                                                                                                       
hi! fzf_info ctermfg=6                                                                                                                                                      
hi! fzf_prompt ctermfg=6                                                                                                                                                    
hi! fzf_spinner ctermfg=6                                                                                                                                                   
hi! fzf_pointer ctermfg=3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let g:fzf_colors = {                                                                                                                                                        
  \ 'fg':      ['fg', 'fzf_fg'],                                                                                                                                            
  \ 'hl':      ['fg', 'fzf_hl'],                                                                                                                                            
  \ 'fg+':     ['fg', 'fzf_fgp'],                                                                                                                                           
  \ 'hl+':     ['fg', 'fzf_hlp'],                                                                                                                                           
  \ 'info':    ['fg', 'fzf_info'],                                                                                                                                          
  \ 'prompt':  ['fg', 'fzf_prompt'],                                                                                                                                        
  \ 'pointer': ['fg', 'fzf_pointer'],                                                                                                                                       
  \ 'spinner': ['fg', 'fzf_spinner'] }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By the way, you can also do this to the highlight attribute of g:fzf_layout.&lt;/p&gt;

&lt;p&gt;FZF will generate the color setting from &lt;code&gt;g:fzf_colors&lt;/code&gt;. To check the generated result, use this vim command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:echo fzf#wrap()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If enerything is good, fzf will trans &lt;code&gt;g:fzf_colors&lt;/code&gt; to the format of FZF_DEFAULT_OPTS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'options': '''--color=info:6,spinner:6,hl:5,fg:14,fg+:3,pointer:3,prompt:6,hl+:5''  --expect=ctrl-v,ctrl-x,ctrl-t', 'sink*': func
tion('283'), 'window': {'highlight': 'fzf_popup', 'width': 0.8, 'height': 0.5}, '_action': {'ctrl-v': 'vsplit', 'ctrl-x': 'split',
 'ctrl-t': 'tab split'}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  More
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Well, how do I know the color number ?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you use 256 color, you can reference this cheat sheet: &lt;a href="https://jonasjacek.github.io/colors/" rel="noopener noreferrer"&gt;https://jonasjacek.github.io/colors/&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Or this tiny script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in {0..255}; do
    printf "\x1b[38;5;${i}m%-9s\x1b[0m" "colour${i}"
    if (( $i % 5 == 0 )); then                            
        printf "\n"                                   
    else                                                  
        printf " "                                    
    fi                                                    
done       
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/junegunn/fzf/blob/a9fba1c8496f7352de55b9fe5f36f23872e5a364/README-VIM.md#L140" rel="noopener noreferrer"&gt;https://github.com/junegunn/fzf/blob/a9fba1c8496f7352de55b9fe5f36f23872e5a364/README-VIM.md#L140&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jonasjacek.github.io/colors/" rel="noopener noreferrer"&gt;https://jonasjacek.github.io/colors/&lt;/a&gt; &lt;/p&gt;

</description>
      <category>vim</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
