• Google Drive on Linux with rclone

    Recently Dropbox hit me with the following announcement:

    Basic users have a three device limit as of March 2019.

    Being the “basic” user, and relying on Dropbox across multiple machines, I got unreasonably upset (“How dare you deny me free access to your service?!”) and started looking for a replacement.

    I already store quite a lot of things in Google Drive, so it seemed like a no brainer: I migrated all my machines to Google Drive overnight. There was but only one problem: Google Drive has official clients for Windows and Mac, but there’s nothing when it comes to Linux.

    I found the Internets to be surprisingly sparse on the subject, and I had to try multiple solutions and spent more time than I’d like researching options.

    The best solution for me turned out to be rclone, which mounts Google Drive as a directory. It requires rclone service to be constantly running in order to access the data, which is a plus for me - I’ve accidentally killed Dropbox daemon in the past and had to deal with conflicts in my files.

    Install rclone (instructions):

    curl https://rclone.org/install.sh | sudo bash
    

    From then on, rclone website some documentation when it comes to the setup. I found it somewhat difficult to parse, so here it is paraphrased:

    Launch rclone config and follow the prompts:

    • n) New remote
    • name> remote
    • Type of storage to configure: Google Drive
    • Leave client_id> and client_secret> blank
    • Scope: 1 \ Full access to all files
    • Leave root_folder_id> and service_account_file> blank
    • Use auto config? y
    • Configure this as a team drive? n
    • Is this OK? y

    From here on, you can interact with your Google Drive by running rclone commands (e.g. rclone ls remote: to list top level files). But I am more interested in a continuous running service and mount is what I need:

    rclone mount remote: $HOME/Drive
    

    Now my Google Drive is accessible at ~/Drive. All that’s left is to make sure the directory is mounted on startup.

    For Ubuntu/Debian, I added the following line to /etc/rc.local (before exit 0, and you need sudo access to edit the file):

    rclone mount remote: $HOME/Drive
    

    For my i3 setup, all I needed was to add the following to ~/.config/i3/config:

    exec rclone mount remote: $HOME/Drive
    

    It’s been working without an issue for a couple of weeks now - and my migration from Dropbox turned out to be somewhat painless and quick.

  • Sane Vim defaults (from Neovim)

    Vim comes with a set of often outdated and counter-intuitive defaults. Vim has been around for around 30 years, and it only makes sense that many defaults did not age well.

    Neovim addresses this issue by being shipped with many default options tweaked for modern editing experience. If you can’t or don’t want to use Neovim - I highly recommend setting some these defaults in your .vimrc:

    if !has('nvim')
      set nocompatible
      syntax on
    
      set autoindent
      set autoread
      set backspace=indent,eol,start
      set belloff=all
      set complete-=i
      set display=lastline
      set formatoptions=tcqj
      set history=10000
      set incsearch
      set laststatus=2
      set ruler
      set sessionoptions-=options
      set showcmd
      set sidescroll=1
      set smarttab
      set ttimeoutlen=50
      set ttyfast
      set viminfo+=!
      set wildmenu
    endif
    

    The defaults above enable some of the nicer editor features, like autoindent (respecting existing indentation), incsearch (search as you type), or wildmenu (enhanced command-line completion). The defaults also smooth out some historical artifacts, like unintuitive backspace behavior. Keep in mind, this breaks compatibility with some older Vim versions (but it’s unlikely to be a problem for most if not all users).

  • Status bar color in Vim terminal mode

    If you’re using a custom color scheme (why wouldn’t you?) in conjunction with a terminal mode in Vim (again, why wouldn’t you?), you may have noticed that the terminal status bar has no respect for your color scheme.

    Run :term, and you’ll be greeted to the default status bar:

    Screenshot of the default terminal mode status line.

    Since terminal mode is still in beta in Vim 8.1, we have to manually set the highlighting groups. It’ll require a bit of digging.

    Navigate to the directory containing your current color scheme. Depending on the plugin manager, the color schemes are located in different places. On Linux, default color schemes often live in /usr/share/vim/vimcurrent/colors. In this example, I’m using PaperColor scheme, and I have it installed using vim-plug in ~/.vim/plugged/papercolor-theme, and colors/PaperColor.vim is the file we’re looking for.

    Search for StatusLine and StatusLineNC (tip: you can do a whole word search in Vim by running /\<StatusLine\>), and note the values used (you might have to jump through a few variables if the color scheme author decided to be fancy). You’re interested in ctermbg, ctermfg, guibg, and guifg.

    You might find something like this:

    hi StatusLine ctermbg=24 ctermfg=254 guibg=#004f87 guifg=#e4e4e4
    hi StatusLineNC ctermbg=252 ctermfg=238 guibg=#d0d0d0 guifg=#444444
    

    Copy those lines to your ~/.vimrc. Change StatusLine to StatusLineTerm, and change StatusLineNC to StatusLineTermNC:

    " Manually set the status line color.
    hi StatusLineTerm ctermbg=24 ctermfg=254 guibg=#004f87 guifg=#e4e4e4
    hi StatusLineTermNC ctermbg=252 ctermfg=238 guibg=#d0d0d0 guifg=#444444
    

    Reload ~/.vimrc (:w | so %), and the terminal mode status line should have the same colors as your color scheme:

    Screenshot of the terminal mode status line with corrected colors.

    Above, hi is a shorthand for highlight, which is used to define highlight group colors. StatusLineTerm and StatusLineTermNC define the highlight groups for terminal mode status line (in active and inactive windows respectively). Options ctermbg and guibg define the background color, and ctermfg and guifg are responsible for the foreground (text) color.

  • My book has been published!

    Over the past six to nine months I’ve been working on a book - Mastering Vim. Mastering Vim is a passion project which is meant to take the reader (you) from zero to a hero (future you): from knowing nothing about Vim, to becoming a power user. I cover many of Vim’s mysterious commands, philosophy behind the beloved editor, configuration tips, a plethora of community created plugins, as well as creating your own plugins.

    A picture of Mastering Vim book cover.

    Mastering Vim was written with support from Packt Publishing and was kindly reviewed by Bram Moolenaar (website) - the creator of Vim. Many people made this book possible, including VimConf Japan crew, who kindly hosted me earlier this year. Thank you to everyone for making Mastering Vim happen!

    Give it a read and let me know what you think, Mastering Vim is available on Amazon!

    P.S: This post, like many others, is written in Vim.

  • Cross-platform vim-plug setup

    I’ve recently switch to vim-plug, a lightweight Vim plugin manager.

    It comes with a little .vimrc snippet which downloads the plugin, but it only works for Unix. I use Vim across all three platforms regularly, so I updated the snippet:

    " Download and install vim-plug (cross platform).
    if empty(glob(
        \ '$HOME/' . (has('win32') ? 'vimfiles' : '.vim') . '/autoload/plug.vim'))
      execute '!curl -fLo ' .
        \ (has('win32') ? '\%USERPROFILE\%/vimfiles' : '$HOME/.vim') . 
        \ '/autoload/plug.vim --create-dirs ' .
        \ 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
      autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
    endif
    

    The above should work across all three major OSes, since Windows 10 recently received curl support.