diff --git a/.Xdefaults b/.Xdefaults new file mode 100644 index 0000000..48ce34f --- /dev/null +++ b/.Xdefaults @@ -0,0 +1,26 @@ +! GENERAL +URxvt*saveLines: 100000 +URxvt*scrollBar: false +URxvt*scrollBar_right: false +URxvt*scrollstyle: rxvt +URxvt*termName: rxvt-256color + +! THEME +URxvt*transparent: true +URxvt*depth: 32 +URxvt*tintColor: Gray +URxvt*shading: 30 +URxvt*foreground: White +URxvt*background: Blue +URxvt*internalBorder: 14 +URxvt*externalBorder: 0 + +! FONT +URxvt*font: xft:Pragmata Pro:pixelsize=12:antialias=true:hinting=true +URxvt*boldFont: xft:Pragmata Pro:bold:pixelsize=12:antialias=true:hinting=true +URxvt*letterSpace: 0 + +! EXT +URxvt.keysym.Shift-Control-V: perl:clipboard:paste +URxvt.iso14755: False +URxvt.perl-ext-common: default,clipboard diff --git a/.Xresources b/.Xresources new file mode 100644 index 0000000..183f7cb --- /dev/null +++ b/.Xresources @@ -0,0 +1,12 @@ +Xft.dpi: 192 +Xft.autohint: 0 +Xft.lcdfilter: lcddefault +Xft.hintstyle: hintfull +Xft.hinting: 1 +Xft.antialias: 1 +Xft.rgba: rgb + +! ------------------------------------------------------------------------------ +! URxvt +! ----------------------------------------------------------------------------- +! see ~/.Xdefaults \ No newline at end of file diff --git a/.aliases b/.aliases new file mode 100644 index 0000000..87f9473 --- /dev/null +++ b/.aliases @@ -0,0 +1,96 @@ +#!/bin/bash + +################################################## +# .aliases +# ------------ +# Loosly based on the amazing work of Jess Frazelle +# +# :author: Levi Olson +# :date: 1 Feb 2018 +# :version: 0.0.1 +################################################## + +# Check for various OS openers. Quit as soon as we find one that works. +for opener in browser-exec xdg-open cmd.exe cygstart "start" open; do + if command -v $opener >/dev/null 2>&1; then + if [[ "$opener" == "cmd.exe" ]]; then + # shellcheck disable=SC2139 + alias open="$opener /c start"; + else + # shellcheck disable=SC2139 + alias open="$opener"; + fi + break; + fi +done + +alias a='emacsclient ~/.bashrc' +alias sf='source ~/.bashrc' +alias ll='ls -ahl --color' +alias l='ls -ahl --color' +alias e='emacsclient' + +alias brightness='sudo tee /sys/class/backlight/acpi_video1/brightness <<<' + +alias pmsyu='sudo pacman -Syu --color=auto' +alias pacman='sudo pacman --color auto' +alias update='sudo pacman -Syu' +alias upmirrors='sudo reflector --score 100 --fastest 25 --sort rate --save /etc/pacman.d/mirrorlist --verbose' + +#git +alias pr='git push origin HEAD' +alias gaa='git add --all .' +alias gcm='git commit -m' +alias gc='git checkout' +alias gd='git diff --patience' +alias gds='git diff --staged --patience' +alias st='git status' +alias gl='git log --decorate' +alias glb='git log --oneline --decorate --all --graph -n15' +alias glv='git log --oneline --decorate --all --graph' + +#dirs +alias thit='cd ~/Projects/work/thit-mobile-api/; clear' +alias gothit='cd ~/go/src/go-thit/; clear' + +#docker +alias dps='docker ps' +alias dpsa='docker ps -a' + +#misc +alias copy='xsel --clipboard --input' +alias paste='xsel --clipboard --output' + +#untar +alias untar='tar xvf' + +#afk +alias afk='i3lock -c 000000' + +# copy file interactive +alias cp='cp -i' + +# move file interactive +alias mv='mv -i' + +# Intuitive map function +# For example, to list all directories that contain a certain file: +# find . -name .gitattributes | map dirname +alias map="xargs -n1" + +# Stopwatch +alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' + +# Always enable colored `grep` output +alias grep='grep --color=auto ' + +# Easier navigation: .., ..., ...., ....., ~ and - +alias ..="cd .." +alias ...="cd ../.." +alias ....="cd ../../.." +alias .....="cd ../../../.." +alias ~="cd ~" +alias -- -="cd -" + +# Allow aliases to be "sudoed" +alias sudo='sudo ' diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 0000000..02fecfb --- /dev/null +++ b/.bash_profile @@ -0,0 +1,45 @@ +#!/bin/bash + +############################################ +# .bash_profile +# --------------- +# Based on the amazing work of Jess Frazelle +############################################ + +# Load the shell dotfiles, and then some: +# * ~/.path can be used to extend `$PATH`. +# * ~/.extra can be used for other settings you don’t want to commit. +for file in ~/.{bash_prompt,aliases,functions,path,dockerfunc,extra,exports}; do + if [[ -r "$file" ]] && [[ -f "$file" ]]; then + # shellcheck source=/dev/null + source "$file" + fi +done +unset file + +# Save multi-line commands as single line in history +shopt -s cmdhist + +# Case-insensitive globbing (used in pathname expansion) +shopt -s nocaseglob + +# Append to the Bash history file, rather than overwriting it +shopt -s histappend + +# Autocorrect typos in path names when using `cd` +shopt -s cdspell + +# Enable some Bash 4 features when possible: +# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux` +# * Recursive globbing, e.g. `echo **/*.txt` +for option in autocd globstar; do + shopt -s "$option" 2> /dev/null +done + +# Add tab completion for SSH hostnames based on ~/.ssh/config +# ignoring wildcards +[[ -e "$HOME/.ssh/config" ]] && complete -o "default" \ + -o "nospace" \ + -W "$(grep "^Host" ~/.ssh/config | \ + grep -v "[?*]" | cut -d " " -f2 | \ + tr ' ' '\n')" scp sftp ssh diff --git a/.bash_prompt b/.bash_prompt new file mode 100644 index 0000000..a06f914 --- /dev/null +++ b/.bash_prompt @@ -0,0 +1,128 @@ +#!/bin/bash +# Shell prompt based on the amazing work of Jess Frazelle. +# Screenshot: http://i.imgur.com/EkEtphC.png + +if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then + export TERM='gnome-256color'; +elif infocmp xterm-256color >/dev/null 2>&1; then + export TERM='xterm-256color'; +fi; + +prompt_git() { + local s=''; + local branchName=''; + + # Check if the current directory is in a Git repository. + if [ "$(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}")" == '0' ]; then + + # check if the current directory is in .git before running git checks + if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then + + if [[ -O "$(git rev-parse --show-toplevel)/.git/index" ]]; then + git update-index --really-refresh -q &> /dev/null; + fi; + + # Check for uncommitted changes in the index. + if ! git diff --quiet --ignore-submodules --cached; then + s+='+'; + fi; + + # Check for unstaged changes. + if ! git diff-files --quiet --ignore-submodules --; then + s+='!'; + fi; + + # Check for untracked files. + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + s+='?'; + fi; + + # Check for stashed files. + if git rev-parse --verify refs/stash &>/dev/null; then + s+='$'; + fi; + + fi; + + # Get the short symbolic ref. + # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit + # Otherwise, just give up. + branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ + git rev-parse --short HEAD 2> /dev/null || \ + echo '(unknown)')"; + + [ -n "${s}" ] && s=" [${s}]"; + + echo -e "${1}${branchName}${blue}${s}"; + else + return; + fi; +} + +cloud="" +if grep -q "^flags.* hypervisor" /proc/cpuinfo && [[ ! -d "/mnt/c/Windows/" ]]; then + cloud="☁️ " +fi + +if tput setaf 1 &> /dev/null; then + tput sgr0; # reset colors + bold=$(tput bold); + reset=$(tput sgr0); + # Solarized colors, taken from http://git.io/solarized-colors. + black=$(tput setaf 0); + blue=$(tput setaf 33); + cyan=$(tput setaf 37); + green=$(tput setaf 64); + orange=$(tput setaf 166); + purple=$(tput setaf 125); + red=$(tput setaf 124); + violet=$(tput setaf 61); + white=$(tput setaf 15); + yellow=$(tput setaf 136); +else + bold=''; + reset="\\e[0m"; + # shellcheck disable=SC2034 + black="\\e[1;30m"; + blue="\\e[1;34m"; + cyan="\\e[1;36m"; + green="\\e[1;32m"; + # shellcheck disable=SC2034 + orange="\\e[1;33m"; + # shellcheck disable=SC2034 + purple="\\e[1;35m"; + red="\\e[1;31m"; + violet="\\e[1;35m"; + white="\\e[1;37m"; + yellow="\\e[1;33m"; +fi; + +# Highlight the user name when logged in as root. +if [[ "${USER}" == "root" ]]; then + userStyle="${red}"; +else + userStyle="${blue}"; +fi; + +# Highlight the hostname when connected via SSH. +if [[ "${SSH_TTY}" ]]; then + hostStyle="${bold}${cyan}"; +else + hostStyle="${cyan}"; +fi; + +# Set the terminal title to the current working directory. +PS1="\\[\\033]0;\\w\\007\\]"; +PS1+="\\[${bold}\\]\\n"; # newline +PS1+="\\[${userStyle}\\]\\u"; # username +PS1+="\\[${white}\\] at "; +PS1+="\\[${hostStyle}\\]${cloud}\\h"; # host +PS1+="\\[${white}\\] in "; +PS1+="\\[${green}\\]\\w"; # working directory +PS1+="\$(prompt_git \"${white} on ${violet}\")"; # Git repository details +PS1+="\\n"; +PS1+="\\[${white}\\]\$ \\[${reset}\\]"; # `$` (and reset color) +export PS1; + +PS2="\\[${yellow}\\]→ \\[${reset}\\]"; +export PS2; diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..fe2307c --- /dev/null +++ b/.bashrc @@ -0,0 +1,45 @@ +#!/bin/bash + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + +# restore last saved path +if [ -f ~/.last_dir ]; then + cd `cat ~/.last_dir` +fi + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if ! shopt -oq posix; then + if [[ -f /usr/share/bash-completion/bash_completion ]]; then + # shellcheck source=/dev/null + . /usr/share/bash-completion/bash_completion + elif [[ -f /etc/bash_completion ]]; then + # shellcheck source=/dev/null + . /etc/bash_completion + fi +fi +for file in /etc/bash_completion.d/* ; do + # shellcheck source=/dev/null + source "$file" +done + +if [[ -f "${HOME}/.bash_profile" ]]; then + # shellcheck source=/dev/null + source "${HOME}/.bash_profile" +fi + +sleep 0.2 +clear diff --git a/.dockerfunc b/.dockerfunc new file mode 100644 index 0000000..98251e6 --- /dev/null +++ b/.dockerfunc @@ -0,0 +1,390 @@ +#!/bin/bash + +###################################### +# .dockerfunc +# ------------ +# Bash wrappers for docker run commands +# +# Based on the amazing work of Jess Frazelle +# +# :author: Levi Olson +# :date: 1 Feb 2018 +# :version: 0.0.1 +###################################### + +export DOCKER_REPO_PREFIX=jess + +dcleanup() { + local containers + mapfile -t containers < <(docker ps -aq 2>/dev/null) + docker rm "${containers[@]}" 2>/dev/null + local volumes + mapfile -t volumes < <(docker ps --filter status=exited -q 2>/dev/null) + docker rm -v "${volumes[@]}" 2>/dev/null + local images + mapfile -t images < <(docker images --filter dangling=true -q 2>/dev/null) + docker rmi "${images[@]}" 2>/dev/null +} +del_stopped() { + local name=$1 + local state + state=$(docker inspect --format "{{.State.Running}}" "$name" 2>/dev/null) + + if [[ "$state" == "false" ]]; then + docker rm "$name" + fi +} +relies_on() { + for container in "$@"; do + local state + state=$(docker inspect --format "{{.State.Running}}" "$container" 2>/dev/null) + + if [[ "$state" == "false" ]] || [[ "$state" == "" ]]; then + echo "$container is not running, starting it for you." + $container + fi + done +} + +###################### +# Container Aliases +# --------------------- +###################### + +aws() { + docker run -it --rm \ + -v "${HOME}/.aws:/root/.aws" \ + --log-driver none \ + --name aws \ + ${DOCKER_REPO_PREFIX}/awscli "$@" +} +cadvisor() { + docker run -d \ + --restart always \ + -v /:/rootfs:ro \ + -v /var/run:/var/run:rw \ + -v /sys:/sys:ro \ + -v /var/lib/docker/:/var/lib/docker:ro \ + -p 1234:8080 \ + --name cadvisor \ + google/cadvisor + + hostess add cadvisor "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' cadvisor)" + browser-exec "http://cadvisor:8080" +} +chrome() { + # add flags for proxy if passed + local proxy= + local map + local args=$* + if [[ "$1" == "tor" ]]; then + relies_on torproxy + + map="MAP * ~NOTFOUND , EXCLUDE torproxy" + proxy="socks5://torproxy:9050" + args="https://check.torproject.org/api/ip ${*:2}" + fi + + del_stopped chrome + + # one day remove /etc/hosts bind mount when effing + # overlay support inotify, such bullshit + docker run -d \ + --memory 6gb \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + -v "${HOME}/Downloads:/root/Downloads" \ + -v "${HOME}/Pictures:/root/Pictures" \ + -v "${HOME}/Torrents:/root/Torrents" \ + -v "${HOME}/.chrome:/data" \ + -v /dev/shm:/dev/shm \ + -v /etc/hosts:/etc/hosts \ + --security-opt seccomp:$HOME/chrome.json \ + --device /dev/snd \ + --device /dev/dri \ + --device /dev/video0 \ + --device /dev/usb \ + --device /dev/bus/usb \ + --group-add audio \ + --group-add video \ + --name chrome \ + ${DOCKER_REPO_PREFIX}/chrome --user-data-dir=/data \ + --proxy-server="$proxy" \ + --host-resolver-rules="$map" "$args" +} +chromium() { + # add flags for proxy if passed + local proxy= + local map + local args=$* + if [[ "$1" == "tor" ]]; then + relies_on torproxy + + map="MAP * ~NOTFOUND , EXCLUDE torproxy" + proxy="socks5://torproxy:9050" + args="https://check.torproject.org/api/ip ${*:2}" + fi + + del_stopped chromium + + # one day remove /etc/hosts bind mount when effing + # overlay support inotify, such bullshit + docker run -d \ + --memory 6gb \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + -v "${HOME}/Downloads:/root/Downloads" \ + -v "${HOME}/Pictures:/root/Pictures" \ + -v "${HOME}/Torrents:/root/Torrents" \ + -v "${HOME}/.chrome:/data" \ + -v /dev/shm:/dev/shm \ + -v /etc/hosts:/etc/hosts \ + --security-opt seccomp:$HOME/chrome.json \ + --device /dev/snd \ + --device /dev/dri \ + --device /dev/video0 \ + --device /dev/usb \ + --device /dev/bus/usb \ + --group-add audio \ + --group-add video \ + --name chromium \ + ${DOCKER_REPO_PREFIX}/chromium --user-data-dir=/data \ + --proxy-server="$proxy" \ + --host-resolver-rules="$map" "$args" +} +firefox() { + del_stopped firefox + relies_on pulseaudio + + docker run -d \ + --memory 6gb \ + --net host \ + --cpuset-cpus 0 \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v "${HOME}/.cache/mozilla:/root/.cache/mozilla" \ + -v "${HOME}/.mozilla:/root/.mozilla" \ + -v "${HOME}/Downloads:/root/Downloads" \ + -v "${HOME}/Pictures:/root/Pictures" \ + -v "${HOME}/Torrents:/root/Torrents" \ + -e "DISPLAY=unix${DISPLAY}" \ + -e GDK_SCALE \ + -e GDK_DPI_SCALE \ + --device /dev/snd \ + --device /dev/dri \ + --name firefox \ + ${DOCKER_REPO_PREFIX}/firefox "$@" +} +gimp() { + del_stopped gimp + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + -v "${HOME}/Pictures:/root/Pictures" \ + -v "${HOME}/.gtkrc:/root/.gtkrc" \ + -e GDK_SCALE \ + -e GDK_DPI_SCALE \ + --name gimp \ + ${DOCKER_REPO_PREFIX}/gimp +} +hollywood() { + docker run --rm -it \ + --name hollywood \ + ${DOCKER_REPO_PREFIX}/hollywood +} +htop() { + docker run --rm -it \ + --pid host \ + --net none \ + --name htop \ + ${DOCKER_REPO_PREFIX}/htop +} +mpd() { + del_stopped mpd + + # adding cap sys_admin so I can use nfs mount + # the container runs as a unpriviledged user mpd + docker run -d \ + --device /dev/snd \ + --cap-add SYS_ADMIN \ + -e MPD_HOST=/var/lib/mpd/socket \ + -v /etc/localtime:/etc/localtime:ro \ + -v /etc/exports:/etc/exports:ro \ + -v "${HOME}/.mpd:/var/lib/mpd" \ + -v "${HOME}/.mpd.conf:/etc/mpd.conf" \ + --name mpd \ + ${DOCKER_REPO_PREFIX}/mpd +} +nes() { + del_stopped nes + local game=$1 + + docker run -d \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + --device /dev/dri \ + --device /dev/snd \ + --name nes \ + ${DOCKER_REPO_PREFIX}/nes "/games/${game}.rom" +} +pulseaudio() { + del_stopped pulseaudio + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + --device /dev/snd \ + -p 4713:4713 \ + --restart always \ + --group-add audio \ + --name pulseaudio \ + ${DOCKER_REPO_PREFIX}/pulseaudio +} +spotify() { + del_stopped spotify + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v "${HOME}/.spotify:/home/spotify/.spotify" \ + -v "${HOME}/.cache/spotify:/home/spotify/.cache/spotify" \ + -e "DISPLAY=unix${DISPLAY}" \ + -e QT_DEVICE_PIXEL_RATIO \ + --security-opt seccomp:unconfined \ + --device /dev/snd \ + --device /dev/dri \ + --group-add audio \ + --group-add video \ + --name spotify \ + ${DOCKER_REPO_PREFIX}/spotify +} +steam() { + del_stopped steam + relies_on pulseaudio + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /etc/machine-id:/etc/machine-id:ro \ + -v /var/run/dbus:/var/run/dbus \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v "${HOME}/.steam:/home/steam" \ + -e "DISPLAY=unix${DISPLAY}" \ + --link pulseaudio:pulseaudio \ + -e PULSE_SERVER=pulseaudio \ + --device /dev/dri \ + --name steam \ + ${DOCKER_REPO_PREFIX}/steam +} +telnet() { + docker run -it --rm \ + --log-driver none \ + ${DOCKER_REPO_PREFIX}/telnet "$@" +} +termboy() { + del_stopped termboy + local game=$1 + + docker run --rm -it \ + --device /dev/snd \ + --name termboy \ + ${DOCKER_REPO_PREFIX}/nes "/games/${game}.rom" +} +tor() { + del_stopped tor + + docker run -d \ + --net host \ + --name tor \ + ${DOCKER_REPO_PREFIX}/tor + + # set up the redirect iptables rules + sudo setup-tor-iptables + + # validate we are running through tor + browser-exec "https://check.torproject.org/" + + # exit current shell + # exit 0 +} +torbrowser() { + del_stopped torbrowser + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + -e GDK_SCALE \ + -e GDK_DPI_SCALE \ + --device /dev/snd \ + --name torbrowser \ + ${DOCKER_REPO_PREFIX}/tor-browser + + # exit current shell + # exit 0 +} +tormessenger() { + del_stopped tormessenger + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + -e GDK_SCALE \ + -e GDK_DPI_SCALE \ + --device /dev/snd \ + --name tormessenger \ + ${DOCKER_REPO_PREFIX}/tor-messenger + + # exit current shell + # exit 0 +} +torproxy() { + del_stopped torproxy + + docker run -d \ + --restart always \ + -v /etc/localtime:/etc/localtime:ro \ + -p 9050:9050 \ + --name torproxy \ + ${DOCKER_REPO_PREFIX}/tor-proxy + + hostess add torproxy "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' torproxy)" +} +traceroute() { + docker run --rm -it \ + --net host \ + ${DOCKER_REPO_PREFIX}/traceroute "$@" +} +transmission() { + del_stopped transmission + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v "${HOME}/Torrents:/transmission/download" \ + -v "${HOME}/.transmission:/transmission/config" \ + -p 9091:9091 \ + -p 51413:51413 \ + -p 51413:51413/udp \ + --name transmission \ + ${DOCKER_REPO_PREFIX}/transmission + + + hostess add transmission "$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' transmission)" + browser-exec "http://transmission:9091" +} +wireshark() { + del_stopped wireshark + + docker run -d \ + -v /etc/localtime:/etc/localtime:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -e "DISPLAY=unix${DISPLAY}" \ + --cap-add NET_RAW \ + --cap-add NET_ADMIN \ + --net host \ + --name wireshark \ + ${DOCKER_REPO_PREFIX}/wireshark +} diff --git a/.exports b/.exports new file mode 100644 index 0000000..d4f69e7 --- /dev/null +++ b/.exports @@ -0,0 +1,35 @@ +#!/bin/bash + +################################################## +# .exports +# ------------ +# Loosly based on the amazing work of Jess Frazelle +# +# :author: Levi Olson +# :date: 1 Feb 2018 +# :version: 0.0.1 +################################################## + +export EDITOR=emacsclient +export TERMINAL=kitty + +# Larger bash history (allow 32³ entries; default is 500) +export HISTSIZE=50000000 +export HISTFILESIZE=$HISTSIZE +export HISTCONTROL=ignoreboth:erasedups + +# Prefer US English and use UTF-8 +export LANG="en_US.UTF-8" +export LC_ALL="en_US.UTF-8" + +# Don't clear the screen after quitting a manual page +export MANPAGER="less -X" + +export JOURNAL_DIR=$HOME/org/journal +export PROJECTS_DIR=$HOME/Projects + +# DPI for GTK apps +export GDK_SCALE=1 +export GDK_DPI_SCALE=1 +export QT_DEVICE_PIXEL_RATIO=1 +export GI_TYPELIB_PATH="/usr/local/lib/girepository-1.0" diff --git a/.functions b/.functions new file mode 100644 index 0000000..5c26b3a --- /dev/null +++ b/.functions @@ -0,0 +1,156 @@ +#!/bin/bash + +################################################## +# .functions +# ------------ +# Based on the amazing work of Jess Frazelle +# +# :author: Levi Olson +# :date: 1 Feb 2018 +# :version: 0.0.1 +################################################## + + +# Simple calculator +calc() { + local result="" + result="$(printf "scale=10;%s\\n" "$*" | bc --mathlib | tr -d '\\\n')" + # └─ default (when `--mathlib` is used) is 20 + + if [[ "$result" == *.* ]]; then + # improve the output for decimal numbers + # add "0" for cases like ".5" + # add "0" for cases like "-.5" + # remove trailing zeros + printf "%s" "$result" | + sed -e 's/^\./0./' \ + -e 's/^-\./-0./' \ + -e 's/0*$//;s/\.$//' + else + printf "%s" "$result" + fi + printf "\\n" +} + +# mkdir, cd into it +mkcd() { + mkdir -p "$@" + cd "$1" +} + +# save path on cd +cd() { + builtin cd $@ + pwd > ~/.last_dir +} + + +# Syntax-highlight JSON strings or files +# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json` +json() { + if [ -t 0 ]; then # argument + python -mjson.tool <<< "$*" | pygmentize -l javascript + else # pipe + python -mjson.tool | pygmentize -l javascript + fi +} + +# Call from a local repo to open the repository on github/bitbucket in browser +# Modified version of https://github.com/zeke/ghwd +repo() { + # Figure out github repo base URL + local base_url + base_url=$(git config --get remote.origin.url) + base_url=${base_url%\.git} # remove .git from end of string + + # Fix git@github.com: URLs + base_url=${base_url//git@github\.com:/https:\/\/github\.com\/} + + # Fix git://github.com URLS + base_url=${base_url//git:\/\/github\.com/https:\/\/github\.com\/} + + # Fix git@bitbucket.org: URLs + base_url=${base_url//git@bitbucket.org:/https:\/\/bitbucket\.org\/} + + # Fix git@gitlab.com: URLs + base_url=${base_url//git@gitlab\.com:/https:\/\/gitlab\.com\/} + + # Validate that this folder is a git folder + if ! git branch 2>/dev/null 1>&2 ; then + echo "Not a git repo!" + exit $? + fi + + # Find current directory relative to .git parent + full_path=$(pwd) + git_base_path=$(cd "./$(git rev-parse --show-cdup)" || exit 1; pwd) + relative_path=${full_path#$git_base_path} # remove leading git_base_path from working directory + + # If filename argument is present, append it + if [ "$1" ]; then + relative_path="$relative_path/$1" + fi + + # Figure out current git branch + # git_where=$(command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null + git_where=$(command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null + + # Remove cruft from branchname + branch=${git_where#refs\/heads\/} + + [[ $base_url == *bitbucket* ]] && tree="src" || tree="tree" + url="$base_url/$tree/$branch$relative_path" + + + echo "Calling $(type open) for $url" + + open "$url" &> /dev/null || (echo "Using $(type open) to open URL failed." && exit 1); +} + +# Get colors in manual pages +man() { + env \ + LESS_TERMCAP_mb="$(printf '\e[1;31m')" \ + LESS_TERMCAP_md="$(printf '\e[1;31m')" \ + LESS_TERMCAP_me="$(printf '\e[0m')" \ + LESS_TERMCAP_se="$(printf '\e[0m')" \ + LESS_TERMCAP_so="$(printf '\e[1;44;33m')" \ + LESS_TERMCAP_ue="$(printf '\e[0m')" \ + LESS_TERMCAP_us="$(printf '\e[1;32m')" \ + man "$@" +} + +# get dbus session +dbs() { + local t=$1 + if [[ -z "$t" ]]; then + local t="session" + fi + + dbus-send --$t --dest=org.freedesktop.DBus \ + --type=method_call --print-reply \ + /org/freedesktop/DBus org.freedesktop.DBus.ListNames +} + +# get the name of a x window +xname(){ + local window_id=$1 + + if [[ -z $window_id ]]; then + echo "Please specifiy a window id, you find this with 'xwininfo'" + + return 1 + fi + + local match_string='".*"' + local match_qstring='"[^"\\]*(\\.[^"\\]*)*"' # NOTE: Adds 1 backreference + + # get the name + xprop -id "$window_id" | \ + sed -nr \ + -e "s/^WM_CLASS\\(STRING\\) = ($match_qstring), ($match_qstring)$/instance=\\1\\nclass=\\3/p" \ + -e "s/^WM_WINDOW_ROLE\\(STRING\\) = ($match_qstring)$/window_role=\\1/p" \ + -e "/^WM_NAME\\(STRING\\) = ($match_string)$/{s//title=\\1/; h}" \ + -e "/^_NET_WM_NAME\\(UTF8_STRING\\) = ($match_qstring)$/{s//title=\\1/; h}" \ + -e "\${g; p}" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc87e2d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.extra diff --git a/.path b/.path new file mode 100644 index 0000000..562c164 --- /dev/null +++ b/.path @@ -0,0 +1,5 @@ +#!/bin/bash + +export GOPATH=$HOME/go +export GOBIN=$GOPATH/bin +export PATH=$GOBIN:$PATH:/opt/android-sdk/platform-tools diff --git a/.xinitrc b/.xinitrc new file mode 100755 index 0000000..a76ee1b --- /dev/null +++ b/.xinitrc @@ -0,0 +1,16 @@ +#!/bin/sh + +########################################## +# .xinitrc +# --------- +########################################## + +#XDG_CONFIG_HOME="$HOME/.config" +#export XDG_CONFIG_HOME + +xrdb -merge ~/.Xresources +xrdb -merge ~/.Xdefaults + +xmodmap $HOME/.xmodmap + +exec i3 diff --git a/.xmodmap b/.xmodmap new file mode 100644 index 0000000..b8cb682 --- /dev/null +++ b/.xmodmap @@ -0,0 +1,3 @@ +clear lock +keycode 66 = Control_L +add Control = Control_L diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..abdc9b0 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +init: + @echo "Let's begin" + @./init.sh diff --git a/bin/browser-exec b/bin/browser-exec new file mode 100755 index 0000000..f7f2254 --- /dev/null +++ b/bin/browser-exec @@ -0,0 +1,48 @@ +#!/bin/bash +############################################################################## +# browser-exec +# ----------- +# Opens a hyperlink in the browser that is currently being run in a container. +# First checks if firefox is running then chrome. +# If neither are running it starts a firefox container. +# +# Usage: +# browser-exec $uri +# +# Based on the amazing work of Jess Frazelle +# +# Dependancies: firefox, chrome, nsenter, xdg +# +# :authors: Levi Olson +# :date: 1 Feb 2018 +# :version: 0.0.1 +############################################################################## +#set -e +set -o pipefail + +browser_exec() { + # check if firefox container is running + firefox_state=$(docker inspect --format "{{.State.Running}}" firefox 2>/dev/null) + if [[ "$firefox_state" == "true" ]]; then + docker exec -i firefox /usr/bin/firefox "$@" 2>/dev/null + else + # check if chrome container is running + chrome_state=$(docker inspect --format "{{.State.Running}}" chrome 2>/dev/null) + if [[ "$chrome_state" == "true" ]]; then + docker exec -i chrome /usr/bin/google-chrome --user-data-dir=/data "$@" 2>/dev/null + else + # maybe we are running in runc + chrome_pid=$(pgrep -f "chrome --user-data" | head -n 1 2>/dev/null) + if [[ ! -z "$chrome_pid" ]]; then + # nsenter the chrome runc container + sudo nsenter -t "$chrome_pid" --pid --user --net --uts --mount --ipc /usr/bin/google-chrome --user-data-dir=/data "$@" 2>/dev/null + else + # neither are currently running so lets try xdg-open + xdg-open "$@" + fi + + fi + fi +} + +browser_exec "$@" diff --git a/bin/docker-cleanup-everything b/bin/docker-cleanup-everything new file mode 100755 index 0000000..f506338 --- /dev/null +++ b/bin/docker-cleanup-everything @@ -0,0 +1,27 @@ +#!/bin/bash +########################################## +# docker-cleanup-everything +# ------------ +# Based on the amazing work of Jess Frazelle +# +# Dependencies: docker +# +# :author: Levi Olson +# :date: 31 Jan 2018 +# :version: 0.0.1 +########################################## + + +cleanup() { + local containers + mapfile -t containers < <(docker ps -aq 2>/dev/null) + docker rm "${containers[@]}" 2>/dev/null + local volumes + mapfile -t volumes < <(docker ps --filter status=exited -q 2>/dev/null) + docker rm -v "${volumes[@]}" 2>/dev/null + local images + mapfile -t images < <(docker images --filter dangling=true -q 2>/dev/null) + docker rmi "${images[@]}" 2>/dev/null +} + +cleanup diff --git a/bin/docker-cleanup-non-running-images b/bin/docker-cleanup-non-running-images new file mode 100755 index 0000000..0709d92 --- /dev/null +++ b/bin/docker-cleanup-non-running-images @@ -0,0 +1,27 @@ +#!/bin/bash +########################################## +# docker-cleanup-non-running-images +# ------------ +# Based on the amazing work of Jess Frazelle +# +# Dependencies: docker +# +# :author: Levi Olson +# :date: 31 Jan 2018 +# :version: 0.0.1 +########################################## +set -e +set -o pipefail + + +cleanup() { + mapfile -t images < <(docker images -q --no-trunc) + for c in $(docker ps -aq); do + image=$(docker inspect --format '{{.Image}}' "$c") + images=( "${images[@]/$image}" ) + done + + docker rmi -f "${images[@]}" 2>&1 || true +} + +cleanup diff --git a/bin/lockscreen b/bin/lockscreen new file mode 100755 index 0000000..55a0596 --- /dev/null +++ b/bin/lockscreen @@ -0,0 +1,19 @@ +#!/bin/bash +########################################## +# lockscreen +# ------------ +# +# Dependencies: docker, i3lock, scrot +# +# Loosly based on the amazing work of Jess Frazelle +# +# :author: Levi Olson +# :date: 31 Jan 2018 +# :version: 0.0.1 +########################################## +set -e + +# subshell +( + i3lock -c 000000 +) diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..f213a2d --- /dev/null +++ b/init.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +###################################### +# init.sh +# --------- +# Symlink ~/dotfiles to $HOME +###################################### + +dir=~/dotfiles # dotfiles directory +backup=~/dotfiles_backup # old dotfiles backup directory +symfiles=".aliases .bash_profile .bash_prompt .bashrc .dockerfunc .exports .functions .path .xinitrc .Xresources .Xdefaults .xmodmap" +symdefaults=".extra" # not in version control + +###################################### + +# create dotfiles_old in homedir +echo "Creating $backup to backup of any existing dotfiles already in ~/" +mkdir -p $backup +echo "...done" + +# change to the dotfiles directory +echo "Changing to the $dir directory" +cd $dir +echo "...done" + +# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks +for file in $symfiles; do + echo "Moving any existing dotfiles from ~/ to $backup" + mv ~/$file $backup/ + echo "Creating symlink to $file in home directory." + ln -s $dir/$file ~/$file +done +echo "...done" + +# create any template/default files not in version control +for file in $symdefaults; do + echo "Creating empty file $file in home directory." + touch $dir/$file + echo "#!/bin/bash\n\n##############################\n# $file\n# ---------------\n##############################\n\n" > $dir/$file +done +echo "...done"