1
0

Merge branch 'master' of github.com:kirsle/.dotfiles

This commit is contained in:
Noah 2015-07-07 23:11:03 +00:00
commit f70f5ba064
6 changed files with 329 additions and 0 deletions

3
.gitmodules vendored
View File

@ -28,3 +28,6 @@
[submodule "home/.vim/bundle/editorconfig-vim"]
path = home/.vim/bundle/editorconfig-vim
url = https://github.com/editorconfig/editorconfig-vim
[submodule "zsh/zgen"]
path = zsh/zgen
url = https://github.com/tarjoilija/zgen

View File

@ -72,6 +72,14 @@ function fish_title
end
end
# `sudo !!` compat for fish shell
function sudo
if test "$argv" = !!
eval command sudo $history[1]
else
command sudo $argv
end
end
# Source local system-specific config.
if test -e ~/.local.fish

View File

@ -19,4 +19,8 @@ indent_size = 4
indent_style = space
indent_size = 2
[*.md]
indent_style = space
indent_size = 2
# format:dosini

123
home/.zshrc Normal file
View File

@ -0,0 +1,123 @@
###
# .zshrc
#
# Kirsle's Global ZSH Configuration
# Updated: 2015-07-07
###
export LANG=en_US.UTF-8 # Unicode
setopt prompt_subst # Allow for dynamic prompts
autoload -U colors && colors # Get color aliases
autoload -U compinit && compinit # Better tab completion
export HISTSIZE=2000 # History settings
export HISTFILE="$HOME/.history"
export SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups
setopt hist_ignore_space
# 256 colors
[[ "$TERM" == "xterm" ]] && export TERM=xterm-256color
# Normalize the PATH
export PATH="/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:${HOME}/bin:${HOME}/go/bin:${HOME}/android/sdk/platform-tools"
export EDITOR="/usr/bin/vim"
# Virtualenv
export WORKON_HOME=~/.virtualenv
# Reload zshrc
alias rezsh="source ${HOME}/.zshrc"
# Allow overriding hostname in the prompt from a local config
export PROMPT_HOSTNAME="%m"
# Source local (system specific) configurations
if [[ -f "${HOME}/.zshrc-local" ]]; then
source "${HOME}/.zshrc-local"
fi
###
# Base shell prompt.
###
# I slowly build the prompt up over multiple places and store it in
# in $base_prompt, so I can modify it before exporting it (for example,
# so the git branch appears before the % at the end of the prompt).
# For the color palette, see: http://www.pixelbeat.org/docs/terminal_colours/
# Use light shades of blue and pink.
local blue="%F{39}"
local pink="%F{213}"
local orange="%F{208}"
local lime="%F{46}"
local cyan="%F{51}"
local base_prompt="%{$blue%}[%{$pink%}%n%{$blue%}@%{$pink%}${PROMPT_HOSTNAME} %{$lime%}%1~"
###
# Include git branch in the prompt
###
git_branch() {
local res=`git branch 2>/dev/null | grep -v '^[^*]' | perl -pe 's/^\*\s+//g'`
if [[ "$res" != "" ]]; then
local res=" ($res)"
fi
echo $res
return $res
}
local git_prompt='%{$cyan%}$(git_branch)%{$reset_color%}'
local base_prompt="${base_prompt}${git_prompt}"
# End the base prompt
local base_prompt="${base_prompt}%{$blue%}]%# %{%f%}"
###
# Set terminal titles automatically
###
precmd() {
print -Pn "\e]0;%n@${PROMPT_HOSTNAME}:%~\a"
}
###############################################################################
# zsh plugins #
###############################################################################
# Load zgen (plugin manager)
source "${HOME}/.dotfiles/zsh/zgen/zgen.zsh"
# Initialize zgen plugins
if ! zgen saved; then
echo "Creating a zgen save"
# Load plugins
zgen oh-my-zsh plugins/virtualenv
zgen oh-my-zsh plugins/virtualenvwrapper
zgen load jimmijj/zsh-syntax-highlighting
zgen load tarruda/zsh-autosuggestions # depends on syntax-highlighting
# Save all to the init script
zgen save
fi
###
# Configure plugin: virtualenvwrapper
###
# Virtualenv prompt. The dynamic part (name of the virtualenv) needs to
# recompute each time so we separate it out into a single-quoted variable.
# See: http://stackoverflow.com/questions/11877551/zsh-not-re-computing-my-shell-prompt
export ZSH_THEME_VIRTUALENV_PREFIX="("
export ZSH_THEME_VIRTUALENV_SUFFIX=")"
local virtualenv_prompt='%{$orange%}$(virtualenv_prompt_info)%{$reset_color%}'
local base_prompt="${virtualenv_prompt}${base_prompt}"
###
# Configure plugin: zsh-autosuggestions
###
export AUTOSUGGESTION_HIGHLIGHT_COLOR="fg=2"
export AUTOSUGGESTION_ACCEPT_RIGHT_ARROW=1
# Finalize and export the prompt
export PROMPT=$base_prompt

190
home/bin/luksvault Executable file
View File

@ -0,0 +1,190 @@
#!/usr/bin/env python3
"""luksvault: Encrypted Disk Images via Luks.
This script makes it easy to set up, mount and unmount encrypted disk images.
It uses an ext4 filesystem by default; this can be overridden with --mkfs,
for example `--mkfs mkfs.vfat`
Usage: luksvault /path/to/disk.img /mnt/point
If the image doesn't exist, you'll be prompted to set it up. If it does exist,
it will be mounted. The setup phase takes the longest and asks for passwords the
most often, but once set up you'll only need to enter the disk image password
(and potentially your sudo password).
To unmount: luksvault -u /path/to/disk.img /mnt/point
See `luksvault --help` for additional options.
--Kirsle
http://sh.kirsle.net/
"""
import sys
import os
import argparse
import logging
import subprocess
logging.basicConfig(format="[%(levelname)s] %(message)s")
console = logging.getLogger("luksvault")
console.setLevel(logging.INFO)
def main(args):
if args.debug:
console.setLevel(logging.DEBUG)
# Test for cryptsetup.
if subprocess.call("which cryptsetup >/dev/null 2>&1", shell=True) != 0:
print("You require cryptsetup to use this script.")
sys.exit(1)
# Get the base name of the file. We remove any file extensions from it,
# and strip dots from it (so if they point to a dotfile like ~/.vault.img
# the basename becomes "vault")
console.debug("File path given via CLI: {}".format(args.image))
basename = os.path.basename(args.image).strip(".").split(".")[0]
console.debug("Base name: {}".format(basename))
if len(basename) == 0:
print("Bad file name for disk image.")
# Mount point exists?
if not os.path.isdir(args.mount):
console.error("Mount point does not exist: {}".format(args.mount))
sys.exit(1)
# Mapper name?
mapper = "luksvault-{}".format(basename)
if args.name:
mapper = args.name
# Does the image exist?
if not os.path.isfile(args.image):
init_image(args, mapper)
sys.exit(0)
# Unmounting it?
if args.unmount:
unmount(args, mapper)
sys.exit(0)
# Mount it.
mount(args, mapper)
sys.exit(0)
def init_image(args, mapper):
"""Initialize the disk image."""
print("The disk image {} does not yet exist.".format(args.image))
answer = input("Create it? [yN] ")
if answer != "y":
sys.exit(1)
# Do we have a size?
size = args.size
if size is None:
try:
size = int(
input("How big do you want the image to be, in MB? ")
)
except:
print("Invalid size; a number was expected.")
sys.exit(1)
# Create it quickly?
if args.fast:
print("Creating fast disk image via fallocate...")
subprocess.call(["fallocate", "-l", "{}M".format(size), args.image])
else:
print("Creating disk image from /dev/urandom...")
subprocess.call(["dd", "if=/dev/urandom",
"of={}".format(args.image),
"bs=1M",
"count={}".format(size)])
# Set up Luks
print("Setting up the Luks format on this disk image...")
subprocess.call(["cryptsetup", "-y", "luksFormat", args.image])
print("REMEMBER: If you lose your password, you won't be able to recover "
"it!")
print("Opening the disk image with Luks and formatting it...")
subprocess.call(["sudo", "cryptsetup", "luksOpen", args.image, mapper])
if not os.path.exists("/dev/mapper/{}".format(mapper)):
console.error("The file /dev/mapper/{} isn't there like I "
"expected!".format(mapper))
sys.exit(1)
subprocess.call("sudo {} /dev/mapper/{}".format(args.mkfs, mapper),
shell=True)
# Mount it.
mount(args, mapper, skip_luks=True)
def mount(args, mapper, skip_luks=False):
"""Mount it."""
# Luks setup.
if not skip_luks:
subprocess.call(["sudo", "cryptsetup", "luksOpen", args.image, mapper])
# Mount it.
subprocess.call(["sudo", "mount",
"/dev/mapper/{}".format(mapper), args.mount])
def unmount(args, mapper):
"""Unmount and tear down Luks."""
print("Unmounting encrypted volume...")
subprocess.call(["sudo", "umount", args.mount])
print("Closing the LUKS context...")
subprocess.call(["sudo", "cryptsetup", "luksClose", mapper])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="luksvault")
parser.add_argument(
"--unmount", "-u",
action="store_true",
help="Unmount the volume.",
)
parser.add_argument(
"--name", "-n",
type=str,
help="The mapper name to use for Luks. Default name is 'luksvault-"
"<basename-of-file>'",
)
parser.add_argument(
"--size", "-s",
type=int,
help="Size of the disk image, in megabytes (e.g. 1024)."
)
parser.add_argument(
"--fast",
action="store_true",
help="Create the disk image quickly (fallocate), but insecurely. "
"It's recommended NOT to use this option (the default is to fully "
"allocate the disk image from /dev/urandom).",
)
parser.add_argument(
"--mkfs",
type=str,
default="mkfs.ext4 -j",
help="The mkfs command prefix you want to use with the encrypted "
"disk image (default is: mkfs.ext4 -j)",
)
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug mode (verbose logging).",
)
parser.add_argument(
"image",
type=str,
help="Path to disk image file.",
)
parser.add_argument(
"mount",
type=str,
help="Path to mount the disk image to.",
)
args = parser.parse_args()
main(args)

1
zsh/zgen Submodule

@ -0,0 +1 @@
Subproject commit 111f9e3fcc1c3d4e261d458cb6d65c5a95ec2f1c