Keeping your Dotfiles

in check with Python

Hi, I am Vipul Gupta 

Available all over the web by vipulgupta2048

blah blah blah ... No one, cares.

Let's get cracking. 

.files?

  • Hidden files and directories
  • Custom application settings 
  • Configuration files
  • .vimrc, .gitconfig, .bashrc

Why should I care?

  • Setup your system again in a few minutes.
  • Worry less, work more.
  • Share them easily.
  • Learn automation
  • Understand how things works behind the scenes.

How to set them up?

  • Symlink them to a git directory
  • Script to install 
    • Bash 
    • Or in this case, Python
  • Push to your Dotfiles repository
    • GitHub
    • GitLab

Bash - The reigning

#!/bin/bash
#Run as root

sudo apt install git nano
git clone https://github.com/vipulgupta2048/dotvfiles
cd dotvfiles
ln -s .nanorc ~

echo "Finished installing Nano Editor"

Python - The contender

from homely.files import symlink
from homely.install import installpkg

installpkg('nano',apt='nano')
symlink('.nanorc')
print("Finished Installing Nano Editor")

What's the point?

  • So with every Homely Update it,
    • It pulls down new changes from the repository
    • ... creates a symlink from [src] to [dst]
    • ... remembers that it created a symlink from [src] to [dst]
    • ... notices when the symlink is no longer asked for, and hence cleanes it later on.
  • Automatic Cleaning

  • NO Password prompt when no TTY available

  • Automatically chooses - brew, yum or apt

  • More powerful from a dotfile manager
  • Functions are idempotent in homely
  • Does everything that a shell script does and more.
  • Ability to run on any system specification
  • With little knowledge of Bash and Python and time, you can get your very own dotfiles setup running in no time. 
  • Setting up your dotfiles, if done right could really help. 

What more can you do?

  • Automation
  • Logging
  • Easier error handling 
  • It's Python. Do whatever with it.

The world is your oyster and the only thing that limits you is what you can see and imagine.

- Vipul Gupta

Stop talking and ...

My Rig - Showoff slide

#!/bin/bash 

# The first script that runs in the system

# Install essentials
sudo apt install git python3.6
pip install homely --user

# Configuring Homely assuming you already have a dotfiles repository
homely add https://www.github.com/vipulgupta2048/dotvfiles.git

# Assuming you have a HOMELY.py script
homely update

Supports multiple repositories without breaking a sweat

Homely Script - Showoff Slide

from homely.files import symlink, mkdir
from homely.install import installpkg

installpkg('nano')
installpkg('fish', apt='fish')
installpkg('geany', apt='geany', yum='geany')

symlink('.nanorc')
symlink('fish/config.fish', '~/.config/fish')
symlink('geany', '~/.config/geany')

print("Finished Setup")

Automatic Cleanup works here as well

Homely Script - Showoff Slide

# lineinfile(filename, contents, where=None)

from homely.files import lineinfile, WHERE_BOT
lineinfile('.bashrc', 'PATH=$HOME/dotfiles/bin:$PATH', WHERE_BOT)

Use lineinfile() to add a line to the end of your .bashrc:

Similarly, you can use homely.files.blockinfile() to add lines to the files.

Automatic Cleanup works here as well

Homely Script - Showoff Slide

from homely.pipinstall import pipinstall
from homely.install import installpkg 

installpkg('python3')

pipinstall('ipython', ['pip3'])

pipinstall('requests', trypips=['pip', 'pip2', 'pip3'])

pipinstall('scrapy', ['pip2'])

You guessed it right, Automatic Cleanup works here as well.

Installing Python Packages through pip using homely.install.pipinstall()

And can easily invoke subprocesses in Python,

what more do you want???

How to Migrate 

it's easy, we got you covered.
# Assuming you have a git repo with an install.sh already:

# HOMELY.py

from os.path import dirname
from homely.system import execute

execute(['install.sh'], stdout="TTY", cwd=dirname(__file__))

References

Buy a lightsaber from someone but,

Rebuild your own with confidence

Cherry pick what you like in other dotfiles. Keep what works, throw out what doesn't.

When you realize the

power of DotFiles

Danke scheon !!

Questions? Any feedback

Did you like the talk? Tell me about it.

Vipul Gupta

Student, Programmer, Writer, Open-Source Contributor, C&H Comics Collector

Tweet @vipulgupta2048

Made with Slides.com