From 273e9a8bdf36bb72d6ed9173214c7afeeece0545 Mon Sep 17 00:00:00 2001 From: Mitch Tishmack Date: Wed, 17 Dec 2014 00:05:10 -0600 Subject: [PATCH] Initial commit. --- .gitignore | 2 + Makefile | 81 ++++++ Vagrantfile | 27 ++ common/.dir_colors | 100 ++++++++ common/.hushlogin | 0 common/.profile.d/00-prelude.sh | 14 + common/.profile.d/01-ps1.sh | 3 + common/.profile.d/10-path.sh | 3 + common/.profile.d/20-functions-path.sh | 42 +++ common/.profile.d/20-functions-ps1.sh | 242 ++++++++++++++++++ common/.profile.d/20-functions.sh | 82 ++++++ common/.profile.d/99-alias.sh | 12 + common/bin/cidr | 142 ++++++++++ common/bin/dns | 36 +++ common/bin/dups | 61 +++++ common/bin/emptydirs | 26 ++ common/bin/gecos | 15 ++ common/bin/hatimerun | 62 +++++ common/bin/ifinfo | 209 +++++++++++++++ common/bin/iso8601 | 13 + common/bin/portchk | 18 ++ common/bin/ptree.pl | 171 +++++++++++++ common/bin/today | 20 ++ common/bin/ts | 12 + common/bin/whoson | 31 +++ emacs/.emacs.d/.gitignore | 7 + emacs/.emacs.d/after-init.el | 12 + emacs/.emacs.d/emacs-package.el | 68 +++++ emacs/.emacs.d/init.el | 66 +++++ emacs/.emacs.d/misc/clang-format.el | 56 ++++ emacs/.emacs.d/mode-defaults.el | 7 + emacs/.emacs.d/modes/cc.el | 28 ++ emacs/.emacs.d/modes/elisp.el | 15 ++ emacs/.emacs.d/modes/go.el | 11 + emacs/.emacs.d/modes/haskell.el | 89 +++++++ emacs/.emacs.d/modes/makefile.el | 14 + emacs/.emacs.d/modes/org.el | 14 + emacs/.emacs.d/modes/perl.el | 12 + emacs/.emacs.d/modes/python.el | 9 + emacs/.emacs.d/modes/ruby.el | 18 ++ emacs/.emacs.d/modes/rust.el | 33 +++ emacs/.emacs.d/modes/shell.el | 18 ++ emacs/.emacs.d/package-settings/autopair.el | 5 + .../.emacs.d/package-settings/color-theme.el | 21 ++ .../package-settings/expand-region.el | 4 + emacs/.emacs.d/package-settings/flycheck.el | 26 ++ emacs/.emacs.d/package-settings/magit-mode.el | 4 + emacs/.emacs.d/package-settings/misc.el | 2 + emacs/.emacs.d/package-settings/multi-term.el | 26 ++ emacs/.emacs.d/package-settings/org.el | 12 + emacs/.emacs.d/package-settings/uniquify.el | 5 + emacs/.emacs.d/settings/clang-format.el | 11 + emacs/.emacs.d/settings/defaults.el | 9 + emacs/.emacs.d/settings/desktop.el | 18 ++ emacs/.emacs.d/settings/dired-x.el | 2 + emacs/.emacs.d/settings/display.el | 25 ++ emacs/.emacs.d/settings/ediff.el | 4 + emacs/.emacs.d/settings/encoding.el | 8 + emacs/.emacs.d/settings/file-templates.el | 45 ++++ emacs/.emacs.d/settings/font.el | 21 ++ emacs/.emacs.d/settings/keybindings.el | 16 ++ emacs/.emacs.d/settings/minimalism.el | 9 + emacs/.emacs.d/settings/misc.el | 33 +++ emacs/.emacs.d/settings/modeline.el | 33 +++ emacs/.emacs.d/settings/modes.el | 4 + emacs/.emacs.d/settings/mouse.el | 9 + emacs/.emacs.d/settings/recentf.el | 5 + emacs/.emacs.d/settings/time.el | 11 + emacs/.emacs.d/settings/tramp.el | 27 ++ emacs/.emacs.d/settings/whitespace.el | 14 + emacs/.emacs.d/templates/elisp.el | 1 + emacs/.emacs.d/templates/perl-module.pm | 18 ++ emacs/.emacs.d/templates/perl.pl | 3 + emacs/.emacs.d/templates/python.py | 3 + emacs/.emacs.d/templates/ruby.rb | 3 + emacs/.emacs.d/templates/shell.ksh | 5 + emacs/.emacs.d/templates/shell.sh | 5 + emacs/.emacs.d/yasnippet/c-mode/assert | 5 + .../.emacs.d/yasnippet/c-mode/compoundliteral | 5 + emacs/.emacs.d/yasnippet/c-mode/doxygen | 10 + emacs/.emacs.d/yasnippet/c-mode/enum | 7 + emacs/.emacs.d/yasnippet/c-mode/for | 7 + emacs/.emacs.d/yasnippet/c-mode/for.1 | 6 + emacs/.emacs.d/yasnippet/c-mode/free | 5 + emacs/.emacs.d/yasnippet/c-mode/function | 8 + .../yasnippet/c-mode/functionprototype | 5 + .../yasnippet/c-mode/functionwithprototype | 9 + emacs/.emacs.d/yasnippet/c-mode/guard | 8 + emacs/.emacs.d/yasnippet/c-mode/ifdef | 7 + emacs/.emacs.d/yasnippet/c-mode/include | 5 + emacs/.emacs.d/yasnippet/c-mode/include.1 | 5 + emacs/.emacs.d/yasnippet/c-mode/main | 7 + emacs/.emacs.d/yasnippet/c-mode/main.1 | 7 + emacs/.emacs.d/yasnippet/c-mode/malloc | 5 + .../yasnippet/c-mode/pragma-clang-ignore | 12 + .../yasnippet/c-mode/pragma-gcc-ignore | 12 + emacs/.emacs.d/yasnippet/c-mode/printf | 7 + emacs/.emacs.d/yasnippet/c-mode/puts | 5 + emacs/.emacs.d/yasnippet/c-mode/static_const | 5 + emacs/.emacs.d/yasnippet/c-mode/struct | 7 + emacs/.emacs.d/yasnippet/c-mode/switch | 11 + emacs/.profile.d/99-alias-emacs.sh | 8 + git/.gitconfig.d/00-user | 3 + git/.gitconfig.d/10-core | 20 ++ git/.gitconfig.d/20-color-setup | 19 ++ git/.gitconfig.d/30-gui-stuff | 5 + git/.gitconfig.d/40-github | 2 + git/.gitconfig.d/5-http | 4 + git/.gitconfig.d/50-gpg | 2 + git/.gitignore | 12 + git/.profile.d/99-alias-git.sh | 2 + haskell/.ghci | 1 + osx/.profile.d/01-ps1-osx.sh | 3 + osx/.profile.d/99-alias.sh | 2 + perl/.perlcriticrc | 49 ++++ perl/.perltidyrc | 22 ++ perl/.profile.d/99-alias-perl.sh | 2 + ruby/.gemrc | 2 + ruby/.maid/rules.rb | 63 +++++ ruby/.profile.d/99-alias-ruby.sh | 2 + ruby/.pryrc | 19 ++ tmux/.profile.d/20-functions-tmux.sh | 11 + tmux/.profile.d/99-alias-tmux.sh | 2 + tmux/.tmux.conf | 160 ++++++++++++ vim/.vimrc | 25 ++ x/.Xdefaults | 17 ++ x/.Xmodmap | 1 + x/.Xresources | 41 +++ x/.profile.d/11-x-modmap.sh | 6 + zsh/.zprofile | 9 + zsh/.zshrc | 141 ++++++++++ 131 files changed, 3173 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 Vagrantfile create mode 100644 common/.dir_colors create mode 100644 common/.hushlogin create mode 100644 common/.profile.d/00-prelude.sh create mode 100644 common/.profile.d/01-ps1.sh create mode 100644 common/.profile.d/10-path.sh create mode 100644 common/.profile.d/20-functions-path.sh create mode 100644 common/.profile.d/20-functions-ps1.sh create mode 100644 common/.profile.d/20-functions.sh create mode 100644 common/.profile.d/99-alias.sh create mode 100755 common/bin/cidr create mode 100755 common/bin/dns create mode 100755 common/bin/dups create mode 100755 common/bin/emptydirs create mode 100755 common/bin/gecos create mode 100755 common/bin/hatimerun create mode 100755 common/bin/ifinfo create mode 100755 common/bin/iso8601 create mode 100755 common/bin/portchk create mode 100755 common/bin/ptree.pl create mode 100755 common/bin/today create mode 100755 common/bin/ts create mode 100755 common/bin/whoson create mode 100644 emacs/.emacs.d/.gitignore create mode 100644 emacs/.emacs.d/after-init.el create mode 100644 emacs/.emacs.d/emacs-package.el create mode 100644 emacs/.emacs.d/init.el create mode 100644 emacs/.emacs.d/misc/clang-format.el create mode 100644 emacs/.emacs.d/mode-defaults.el create mode 100644 emacs/.emacs.d/modes/cc.el create mode 100644 emacs/.emacs.d/modes/elisp.el create mode 100644 emacs/.emacs.d/modes/go.el create mode 100644 emacs/.emacs.d/modes/haskell.el create mode 100644 emacs/.emacs.d/modes/makefile.el create mode 100644 emacs/.emacs.d/modes/org.el create mode 100644 emacs/.emacs.d/modes/perl.el create mode 100644 emacs/.emacs.d/modes/python.el create mode 100644 emacs/.emacs.d/modes/ruby.el create mode 100644 emacs/.emacs.d/modes/rust.el create mode 100644 emacs/.emacs.d/modes/shell.el create mode 100644 emacs/.emacs.d/package-settings/autopair.el create mode 100644 emacs/.emacs.d/package-settings/color-theme.el create mode 100644 emacs/.emacs.d/package-settings/expand-region.el create mode 100644 emacs/.emacs.d/package-settings/flycheck.el create mode 100644 emacs/.emacs.d/package-settings/magit-mode.el create mode 100644 emacs/.emacs.d/package-settings/misc.el create mode 100644 emacs/.emacs.d/package-settings/multi-term.el create mode 100644 emacs/.emacs.d/package-settings/org.el create mode 100644 emacs/.emacs.d/package-settings/uniquify.el create mode 100644 emacs/.emacs.d/settings/clang-format.el create mode 100644 emacs/.emacs.d/settings/defaults.el create mode 100644 emacs/.emacs.d/settings/desktop.el create mode 100644 emacs/.emacs.d/settings/dired-x.el create mode 100644 emacs/.emacs.d/settings/display.el create mode 100644 emacs/.emacs.d/settings/ediff.el create mode 100644 emacs/.emacs.d/settings/encoding.el create mode 100644 emacs/.emacs.d/settings/file-templates.el create mode 100644 emacs/.emacs.d/settings/font.el create mode 100644 emacs/.emacs.d/settings/keybindings.el create mode 100644 emacs/.emacs.d/settings/minimalism.el create mode 100644 emacs/.emacs.d/settings/misc.el create mode 100644 emacs/.emacs.d/settings/modeline.el create mode 100644 emacs/.emacs.d/settings/modes.el create mode 100644 emacs/.emacs.d/settings/mouse.el create mode 100644 emacs/.emacs.d/settings/recentf.el create mode 100644 emacs/.emacs.d/settings/time.el create mode 100644 emacs/.emacs.d/settings/tramp.el create mode 100644 emacs/.emacs.d/settings/whitespace.el create mode 100644 emacs/.emacs.d/templates/elisp.el create mode 100644 emacs/.emacs.d/templates/perl-module.pm create mode 100644 emacs/.emacs.d/templates/perl.pl create mode 100644 emacs/.emacs.d/templates/python.py create mode 100644 emacs/.emacs.d/templates/ruby.rb create mode 100755 emacs/.emacs.d/templates/shell.ksh create mode 100755 emacs/.emacs.d/templates/shell.sh create mode 100644 emacs/.emacs.d/yasnippet/c-mode/assert create mode 100644 emacs/.emacs.d/yasnippet/c-mode/compoundliteral create mode 100644 emacs/.emacs.d/yasnippet/c-mode/doxygen create mode 100644 emacs/.emacs.d/yasnippet/c-mode/enum create mode 100644 emacs/.emacs.d/yasnippet/c-mode/for create mode 100644 emacs/.emacs.d/yasnippet/c-mode/for.1 create mode 100644 emacs/.emacs.d/yasnippet/c-mode/free create mode 100644 emacs/.emacs.d/yasnippet/c-mode/function create mode 100644 emacs/.emacs.d/yasnippet/c-mode/functionprototype create mode 100644 emacs/.emacs.d/yasnippet/c-mode/functionwithprototype create mode 100644 emacs/.emacs.d/yasnippet/c-mode/guard create mode 100644 emacs/.emacs.d/yasnippet/c-mode/ifdef create mode 100644 emacs/.emacs.d/yasnippet/c-mode/include create mode 100644 emacs/.emacs.d/yasnippet/c-mode/include.1 create mode 100644 emacs/.emacs.d/yasnippet/c-mode/main create mode 100644 emacs/.emacs.d/yasnippet/c-mode/main.1 create mode 100644 emacs/.emacs.d/yasnippet/c-mode/malloc create mode 100644 emacs/.emacs.d/yasnippet/c-mode/pragma-clang-ignore create mode 100644 emacs/.emacs.d/yasnippet/c-mode/pragma-gcc-ignore create mode 100644 emacs/.emacs.d/yasnippet/c-mode/printf create mode 100644 emacs/.emacs.d/yasnippet/c-mode/puts create mode 100644 emacs/.emacs.d/yasnippet/c-mode/static_const create mode 100644 emacs/.emacs.d/yasnippet/c-mode/struct create mode 100644 emacs/.emacs.d/yasnippet/c-mode/switch create mode 100644 emacs/.profile.d/99-alias-emacs.sh create mode 100644 git/.gitconfig.d/00-user create mode 100644 git/.gitconfig.d/10-core create mode 100644 git/.gitconfig.d/20-color-setup create mode 100644 git/.gitconfig.d/30-gui-stuff create mode 100644 git/.gitconfig.d/40-github create mode 100644 git/.gitconfig.d/5-http create mode 100644 git/.gitconfig.d/50-gpg create mode 100644 git/.gitignore create mode 100644 git/.profile.d/99-alias-git.sh create mode 100644 haskell/.ghci create mode 100644 osx/.profile.d/01-ps1-osx.sh create mode 100644 osx/.profile.d/99-alias.sh create mode 100644 perl/.perlcriticrc create mode 100644 perl/.perltidyrc create mode 100644 perl/.profile.d/99-alias-perl.sh create mode 100644 ruby/.gemrc create mode 100755 ruby/.maid/rules.rb create mode 100644 ruby/.profile.d/99-alias-ruby.sh create mode 100644 ruby/.pryrc create mode 100644 tmux/.profile.d/20-functions-tmux.sh create mode 100644 tmux/.profile.d/99-alias-tmux.sh create mode 100644 tmux/.tmux.conf create mode 100644 vim/.vimrc create mode 100644 x/.Xdefaults create mode 100644 x/.Xmodmap create mode 100644 x/.Xresources create mode 100644 x/.profile.d/11-x-modmap.sh create mode 100644 zsh/.zprofile create mode 100644 zsh/.zshrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f93f93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vagrant +.checksum diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..87d66e5 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +DOTDEE=update-dotdee +STOW=xstow +STOWOPTS=-f +DOTGIT=.gitconfig +DOTPRO=.profile +GITCONFIG=git/.gitconfig +GITCONFIGDOTDEE=$(GITCONFIG).d +GITCONFIGCKSUM=$(GITCONFIGDOTDEE)/.checksum +DOTPROFILE=common/.profile +DOTPROFILEDOTDEE=$(DOTPROFILE).d +DOTPROFILECKSUM=$(DOTPROFILEDOTDEE)/.checksum +PWD=$(shell pwd) + +.PHONY: common emacs git ruby haskell perl tmux vim zsh list home osx linux ws + +home: gitconfig dotprofile + $(DOTDEE) ../$(DOTPRO) + $(DOTDEE) ../$(DOTGIT) + +ws: common emacs git ruby haskell perl tmux vim zsh home + +all: home + +dotprofile: $(DOTPROFILECKSUM) + +gitconfig: $(GITCONFIGCKSUM) + +$(GITCONFIG): + touch $(GITCONFIG) + +$(GITCONFIGCKSUM): $(GITCONFIG) + $(DOTDEE) $(GITCONFIG) + +list: + echo common emacs git ruby haskell perl tmux vim zsh + +clean: + $(STOW) -D common emacs git ruby haskell perl tmux vim zsh osx + -rm $(GITCONFIG) $(GITCONFIGCKSUM) $(DOTPROFILE) $(DOTPROFILECKSUM) + +gitconfig: $(GITCONFIG) + +$(DOTPROFILE): + touch $(DOTPROFILE) + +$(DOTPROFILECKSUM): $(DOTPROFILE) + $(DOTDEE) $(DOTPROFILE) + +common: $(DOTFILECKSUM) + $(STOW) $(STOWOPTS) common + +# Specific stows, nothing special +git: gitconfig + $(STOW) git + +emacs: + $(STOW) emacs # $@? + +osx: + $(STOW) osx + +linux: + $(STOW) linux + +x: + $(STOW) x + +ruby: + $(STOW) ruby + +zsh: + $(STOW) zsh + +vim: + $(STOW) vim + +haskell: + $(STOW) haskell + +perl: + $(STOW) perl diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..29e8fc1 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,27 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +ENV['VAGRANT_DOTFILE_PATH'] = "/tmp/vagrant" +Vagrant.configure("2") do |config| + config.vm.box = "precise64" + config.vm.provision "shell", + privileged: false, + inline: "if [ ! -e /var/tmp/.done ]; then +sudo apt-get clean +sudo rm -fr /var/lib/apt/lists +sudo apt-get update +# git 2.N+ instead of ass old git +sudo apt-get install -y -q python-software-properties +sudo add-apt-repository ppa:git-core/ppa +sudo apt-get update +sudo apt-get install -y -q xstow python-pip git pax zsh +sudo pip install update-dotdee +sudo usermod -s /bin/zsh vagrant +mkdir /home/vagrant/dotfiles +sudo mount -o bind /vagrant /home/vagrant/dotfiles +touch /var/tmp/.done +fi +cd ~/dotfiles +make ws all +" +end diff --git a/common/.dir_colors b/common/.dir_colors new file mode 100644 index 0000000..b17860e --- /dev/null +++ b/common/.dir_colors @@ -0,0 +1,100 @@ +COLOR tty + +TERM ansi +TERM color-xterm +TERM con132x25 +TERM con132x30 +TERM con132x43 +TERM con132x60 +TERM con80x25 +TERM con80x28 +TERM con80x30 +TERM con80x43 +TERM con80x50 +TERM con80x60 +TERM cons25 +TERM console +TERM cygwin +TERM dtterm +TERM eterm-color +TERM Eterm +TERM gnome +TERM konsole +TERM kterm +TERM linux +TERM linux-c +TERM mach-color +TERM putty +TERM rxvt +TERM rxvt-cygwin +TERM rxvt-cygwin-native +TERM rxvt-unicode +TERM screen +TERM screen-bce +TERM screen-w +TERM screen.linux +TERM vt100 +TERM xterm +TERM xterm-256color +TERM xterm-color +TERM xterm-debian + +# Below are the color init strings for the basic file types. A color init +# string consists of one or more of the following numeric codes: +# Attribute codes: +# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed +# Text color codes: +# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white +# Background color codes: +# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white +NORMAL 00 # global default, although everything should be something. +FILE 00 # normal file +DIR 01;34 # directory +LINK 01;36 # symbolic link. (If you set this to 'target' instead of a + # numerical value, the color will match the file pointed to) +FIFO 40;33 # pipe +SOCK 01;35 # socket +DOOR 01;35 # door +BLK 40;33;01 # block device driver +CHR 40;33;01 # character device driver +ORPHAN 01;05;37;41 # orphaned syminks +MISSING 01;05;37;41 # ... and the files they point to + +# This is for files with execute permission: +EXEC 01;32 + +# List any file extensions like '.gz' or '.tar' that you would like ls +# to colorize below. Put the extension, a space, and the color init string. +# (and any comments you want to add after a '#') + +.cmd 01;32 # executables (bright green) +.exe 01;32 +.com 01;32 +.btm 01;32 +.bat 01;32 +.sh 01;32 +.csh 01;32 +.ksh 01;32 +.zsh 01;32 + +.tar 01;31 # archives / compressed (bright red) +.tgz 01;31 +.arj 01;31 +.taz 01;31 +.lzh 01;31 +.zip 01;31 +.z 01;31 +.Z 01;31 +.gz 01;31 +.bz2 01;31 +.bz 01;31 +.tbz2 01;31 +.tz 01;31 +.deb 01;31 +.rpm 01;31 +.rar 01;31 # app-arch/rar +.ace 01;31 # app-arch/unace +.zoo 01;31 # app-arch/zoo +.cpio 01;31 # app-arch/cpio +.7z 01;31 # app-arch/p7zip +.rz 01;31 # app-arch/rzip diff --git a/common/.hushlogin b/common/.hushlogin new file mode 100644 index 0000000..e69de29 diff --git a/common/.profile.d/00-prelude.sh b/common/.profile.d/00-prelude.sh new file mode 100644 index 0000000..e6a0a92 --- /dev/null +++ b/common/.profile.d/00-prelude.sh @@ -0,0 +1,14 @@ +# common/.profile.d/00-prelude.sh +# -*- mode: Shell-script; -*- +# Common .profile +# +# This file is generated from dotdee and managed from stow. +# +# Manual editing discouraged. + + +# Common variables for use later +_uname=$(uname) +_uname_n=$(uname -n) +_hostname=$(hostname) +export _uname _uname_n _hostname diff --git a/common/.profile.d/01-ps1.sh b/common/.profile.d/01-ps1.sh new file mode 100644 index 0000000..4bac252 --- /dev/null +++ b/common/.profile.d/01-ps1.sh @@ -0,0 +1,3 @@ +# common/.profile.d/01-ps1.sh +# Default if not already overridden +_host=${_host:=${_uname_n}} diff --git a/common/.profile.d/10-path.sh b/common/.profile.d/10-path.sh new file mode 100644 index 0000000..5d96d99 --- /dev/null +++ b/common/.profile.d/10-path.sh @@ -0,0 +1,3 @@ +# common/.profile.d/10-path.sh +PATH="${PATH}:${HOME}/bin" +export PATH diff --git a/common/.profile.d/20-functions-path.sh b/common/.profile.d/20-functions-path.sh new file mode 100644 index 0000000..908e923 --- /dev/null +++ b/common/.profile.d/20-functions-path.sh @@ -0,0 +1,42 @@ +# common/.profile.d/20-functions-path.sh +# cat out a : separated env variable +# variable is the parameter +cat_env() +{ + set | grep '^'"$1"'=' > /dev/null 2>&1 && eval "echo \$$1" | tr ':' ' +' | awk '!/^\s+$/' | awk '!/^$/' +} + +# Convert a line delimited input to : delimited +to_env() +{ + awk '!a[$0]++' < /dev/stdin | tr -s ' +' ':' | sed -e 's/\:$//' | awk 'NF > 0' +} + +# Unshift a new value onto the env var +# first arg is ENV second is value to unshift +# basically prepend value to the ENV variable +unshift_env() +{ + new=$(eval "echo $2; echo \$$1" | to_env) + eval "$1=${new}; export $1" +} + +# Opposite of above, but echos what was shifted off +shift_env() +{ + first=$(cat_env "$1" | head -n 1) + rest=$(cat_env "$1" | awk '{if (NR!=1) {print}}' | to_env) + eval "$1=$rest; export $1" + echo "${first}" +} + +# push $2 to $1 on the variable +push_env() +{ + have=$(cat_env "$1") + new=$(printf "%s +%s" "$have" "$2" | to_env) + eval "$1=$new; export $1" +} diff --git a/common/.profile.d/20-functions-ps1.sh b/common/.profile.d/20-functions-ps1.sh new file mode 100644 index 0000000..27c292d --- /dev/null +++ b/common/.profile.d/20-functions-ps1.sh @@ -0,0 +1,242 @@ +# common/.profile.d/20-functions-ps1.sh + +# Get user name of current user even if +# $USER isn't set +# Use id if we don't have $USER +user_name() +{ + if [ -z $USER ]; then + echo $(id | awk -F\( '{print $2}' | sed -e 's/[)].*//g') + else + echo $USER + fi +} + +# duh +am_i_root() +{ + [ "$(user_name)" = 'root' ] +} + +userps1name= +hostps1name= + +host_name() +{ + name='' + case $(os_type) in + osx) name=$(hostname -s) ;; + *) name=$(uname -n) ;; + esac + + echo $name +} +host_ps1name() +{ + if [[ ${hostps1name:+1} != 1 ]]; then + hostps1name=$(host_name) + if [[ ${pscolors:+1} == 1 ]]; then + hostps1name="%{$fg[blue]%}$hostps1name%{$reset_color%}" + fi + fi + echo $hostps1name +} + +user_ps1name() +{ + if [[ ${userps1name:+1} != 1 ]]; then + case $(user_name) in + mitch) + userps1name='me' + if [[ ${pscolors:+1} == 1 ]]; then + userps1name="%{$fg[blue]%}$userps1name%{$reset_color%}" + fi + ;; + root) + userps1name='root' + if [[ ${pscolors:+1} == 1 ]]; then + userps1name="%{$fg[red]%}$userps1name%{$reset_color%}" + fi + ;; + *) + userps1name=$(user_name) + if [[ ${pscolors:+1} == 1 ]]; then + userps1name="%{$fg[cyan]%}$userps1name%{$reset_color%}" + fi + ;; + esac + fi + echo $userps1name +} + +# using who am i, see if our pty is owned by someone else. +user_ptyname() +{ + name=$(who am i | sed -e "s/[ ].*//1") + [ ${name} == '' ] && name=$LOGNAME + echo $name +} + +ps1_user_host() +{ + echo "$(user_ps1name)@$(host_ps1name)" +} + +ps1_special() +{ + am_i_root + [ $? -eq 0 ] && echo '# ' || echo '$ ' +} + +ps1() +{ + echo "$(ps1_user_host) $(ps1_special)" +} + +ostype='' +oskernel='' +osarch='' +osmajor='' +osminor='' +osversion='' +osuname_s='' +osrelease='' +osprefix='' +osreleasefile='' + +# where /etc/*release files exist +archreleasefile='/etc/arch-release' +debianreleasefile='/etc/debian_version' +susereleasefile='/etc/SuSE-release' +redhatreleasefile='/etc/Redhat-release' +solarisreleasefile='/etc/release' +freebsdreleasefile='/etc/freebsd-update.conf' + +os_release() +{ + case $(os_uname_s) in + Linux) osrelease=$(cat $osreleasefile) ;; + Darwin) osrelease=$(sw_vers -productVersion) ;; + bsd) osrelease=$(uname -r) ;; + *) osrelease='' ;; + esac + echo $osrelease +} + +os_kernel() +{ + if [[ ${oskernel:+1} != 1 ]]; then + oskernel=$(uname -r) + fi + echo $oskernel +} + +os_arch() +{ + if [[ ${osarch:+1} != 1 ]]; then + osarch=$(uname -m) + fi + echo $osarch +} + +os_uname_s() +{ + if [[ ${os_uname_s:+1} != 1 ]]; then + osuname_s=$(uname -s) + fi + echo $osuname_s +} + +function os_type { + if [[ ${ostype:+1} != 1 ]]; then + if [[ -f $archreleasefile ]]; then + ostype='arch' + osreleasefile=$archreleasefile + elif [[ -f $debianreleasefile ]]; then + ostype='debian' + osreleasefile=$debianreleasefile + elif [[ -f $susereleasefile ]]; then + ostype='suse' + osreleasefile=$susereleasefile + elif [[ -f $redhatreleasefile ]]; then + ostype='redhat' + osreleasefile=$redhatreleasefile + elif [[ $(os_uname_s) == 'SunOS' ]]; then + ostype='sun' + elif [[ $(os_uname_s) == 'Darwin' ]]; then + ostype='osx' + elif [[ -f $freebsdreleasefile ]]; then + ostype='bsd' + else + echo "No idea what os type this is." + fi + fi + echo $ostype +} + +os_major() +{ + if [[ ${osmajor:+1} != 1 ]]; then + case $(os_type) in + arch) osmajor='arch' ;; + debian) osmajor=$(os_release | sed -e 's/\.[0-9]\{1\}//2') ;; + suse) + osmajor=$(os_release | grep 'VER' | sed -e 's/.*\=\ //g') ;; + redhat) osmajor='zomg' ;; + sun) osmajor=$(uname -r) ;; + osx) osmajor=$(os_release | sed -e 's/\.[0-9]\{1\}//2') ;; + bsd) osmajor=$(os_release | sed -e 's/\.*//') ;; + *) osmajor='?' + esac + fi + echo $osmajor +} + +os_minor() +{ + if [[ ${osminor:+1} != 1 ]]; then + case $(os_type) in + arch) osminor='zomg' ;; + debian) osminor=$(os_release | sed -e 's/[0-9]\.[0-9]\{1\}\.//1') ;; + suse) + osminor=$(os_release | grep 'PATCH' | sed -e 's/.*\=\ //g') ;; + redhat) osminor='zomg' ;; + sun) osminor=$(uname -r) ;; + osx) osminor=$(os_release | sed -e 's/10\.[0-9]\{1\}\.//1') ;; + bsd) osminor=$(os_release | sed -e 's/\d+\.[0-9]\{1\}\-//1') ;; + *) osminor='?' + esac + fi + echo $osminor +} + +os_version() +{ + if [[ ${osversion:+1} != 1 ]]; then + case $(os_type) in + arch) osversion='zomg' ;; + debian) osversion=$(os_release) ;; + suse) osversion="${osmajor}u${osminor}" ;; + redhat) osversion='zomg' ;; + sun) osversion=$osmajor ;; + osx) osversion=$(os_release) ;; + bsd) osversion="${osmajor}.${osminor}" ;; + *) osversion='wtf?' ;; + esac + fi + echo $osversion +} + +os_prefix() +{ + if [[ ${osprefix:+1} != 1 ]]; then + case $(os_type) in + osx) osprefix="$(os_major)-$(os_uname_s)-$(os_arch)" ;; + *) osprefix="$(os_type)-$(os_uname_s)-$(os_arch)" ;; + esac + fi + echo $osprefix +} + +# setup the one thing we need for all of the functions. +os_type > /dev/null 2>&1 diff --git a/common/.profile.d/20-functions.sh b/common/.profile.d/20-functions.sh new file mode 100644 index 0000000..3cc7dfe --- /dev/null +++ b/common/.profile.d/20-functions.sh @@ -0,0 +1,82 @@ +# common/.profile.d/20-functions.sh +# Remove a line matched in $HOME/.ssh/known_hosts for when there are legit +# host key changes. +nukehost() +{ + if [ -z "$1" ]; then + echo "Usage: nukehost " + echo " Removes from ssh known_host file." + else + sed -i -e "/$1/d" ~/.ssh/known_hosts + fi +} + +# Cheap copy function to make copying a file via ssh from one host +# to another less painful, use pipeviewer to give some idea as to progress. +ssh-copyfile() +{ + if [ -z "$1" -o -z "$2" ]; then + echo "Usage: copy source:/file/location destination:/file/location" + else + srchost="$(echo "$1" | awk -F: '{print $1}')" + src="$(echo "$1" | awk -F: '{print $2}')" + dsthost="$(echo "$2" | awk -F: '{print $1}')" + dst="$(echo "$2" | awk -F: '{print $2}')" + size=$(ssh "$srchost" du -hs "$src" 2> /dev/null) + size=$(echo "${size}" | awk '{print $1}') + echo "Copying $size to $dst" + ssh "$srchost" "/bin/cat \$src" 2> /dev/null | pv -cb -N copied - | ssh "$dsthost" "/bin/cat - > \$dst" 2> /dev/null + fi +} + +# extract function to automate being lazy at extracting archives. +extract() +{ + if [ -f "$1" ]; then + case ${1} in + *.tar.bz2|*.tbz2|*.tbz) bunzip2 -c "$1" | tar xvf -;; + *.tar.gz|*.tgz) gunzip -c "$1" | tar xvf -;; + *.tz|*.tar.z) zcat "$1" | tar xvf -;; + *.tar.xz|*.txz|*.tpxz) xz -d -c "$1" | tar xvf -;; + *.bz2) bunzip2 "$1";; + *.gz) gunzip "$1";; + *.jar|*.zip) unzip "$1";; + *.rar) unrar x "$1";; + *.tar) tar -xvf "$1";; + *.z) uncompress "$1";; + *.rpm) rpm2cpio "$1" | cpio -idv;; + *) echo "Unable to extract <$1> Unknown extension." + esac + else + print "File <$1> does not exist." + fi +} + +# Tcsh compatibility so I can be a lazy bastard and paste things directly +# if/when I need to. +setenv() +{ + export "$1=$2" +} + +# Just to be lazy, set/unset the DEBUG env variable used in my scripts +debug() +{ + if [ -z "$DEBUG" ]; then + if [ -z "$1" ]; then + echo Setting DEBUG to "$1" + setenv DEBUG "$1" + else + echo Setting DEBUG to default + setenv DEBUG default + fi + else + echo Unsetting DEBUG + unset DEBUG + fi +} + +login_shell() +{ + [[ $- == *i* ]] +} diff --git a/common/.profile.d/99-alias.sh b/common/.profile.d/99-alias.sh new file mode 100644 index 0000000..b4949dd --- /dev/null +++ b/common/.profile.d/99-alias.sh @@ -0,0 +1,12 @@ +# common/.profile.d/99-alias.sh +alias s="\$(which ssh)" +alias quit='exit' +alias cr='reset; clear' +alias a=ag +alias n=noglob +alias l=ls +alias L='ls -dal' +alias tl='tmux ls' +alias cleandir="find . -type f \( -name '*~' -o -name '#*#' -o -name '.*~' -o -name '.#*#' -o -name 'core' -o -name 'dead.letter*' \) | grep -v auto-save-list | xargs -t rm" +which less > /dev/null 2>&1 +[ $? = 0 ] && alias T='less -f +F' || alias T='tail -f' diff --git a/common/bin/cidr b/common/bin/cidr new file mode 100755 index 0000000..77e9e04 --- /dev/null +++ b/common/bin/cidr @@ -0,0 +1,142 @@ +#!/usr/bin/env perl +# +# Convert input ip/cidr|netmask|hexnetmask to useable network information. +# + +use strict; +use warnings; +use Socket; +use Sys::Hostname; + +# +# Globalish vars +# +$ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin'; # Paranoia, know thy name! +my ($fqdn_regexp) = qr/([0-9,a-z,A-Z,\-,\_]+)\.([0-9,a-z,A-Z,\-,\_]+)\.(com|gov)/; + +# +# converts a 1-word (4 byte) signed or unsigned integer into a dotted decimal +# ip address. +# +sub int2ip { + my $n=int(pop); + return(sprintf("%d.%d.%d.%d", ($n>>24)&0xff,($n>>16)&0xff, + ($n>>8)&0xff,$n&0xff)); +}; + +# +# Convert a host/ip/netmask/cidr/etc.... to a hash of information +# Example: host.domain.tld/24 will get the ip and calculate the netmask info +# equally if host.domain.tld corresponds with 1.2.3.4 the following is valid +# 1.2.3.4/255.255.255.0 would obtain the same information. +# +# die()'s if anything isn't kosher. +# +# Ultra long function, probably needs to be looked at for condensing/splitting. +# +sub cidr2raw { + my $rawinput = pop; + my ($lhs, $rhs, $j, $uip) = (undef, undef, undef, undef); + my ($ucidr) = 0; + my ($network, $bits, $netmask, $broadcast, $low, $high); + + if ($rawinput =~ qr/(.*)\/(.*)/){ + $lhs = $1; $rhs = $2; + }else{ + die "Input: $rawinput not expected.\n"; + }; + + # + # Handle ip/hostname for left hand side. + if ($lhs =~ qr/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ + foreach my $dotted (($1,$2,$3,$4)){ + if (($dotted > 255) or ($dotted < 0)){ + die "FATAL: ipv4 address entered, $lhs entered is impossible, $dotted is not between 0-255.\n"; + }; + }; + $uip = inet_ntoa(scalar gethostbyname($lhs)); + die "FATAL: Cannot determine hostname for $lhs$!\n" if (!defined($lhs)); + }elsif ($lhs =~ $fqdn_regexp){ + my $tmp = gethostbyname($lhs); + die "FATAL: Cannot determine ip for $lhs" if (!defined($tmp)); + $uip = inet_ntoa($tmp); + }else{ + die "FATAL: host value not fully qualified, or not an ip <$lhs>\n"; + }; + + # + # Handle the netmask/cidr for the right hand side, + # + # All input netmasks are converted to a cidr address for notation + if ($rhs =~ qr/^(\d+)$/){ # /cidr + $ucidr = $1; + die "FATAL: Invalid CIDR <$ucidr>.$!\n" if (($ucidr > 32) or ($ucidr < 0)); + }elsif ($rhs =~ qr/(0[xX])?([0-9,a-f,A-F]{7})/){ # /0xhexnetmask + my $trimmed = $2; + my $insane = 0; + foreach my $byte (split('', unpack("B32", pack("H*", $trimmed)))){ + ($byte) ? $ucidr++ : $insane++; + die "FATAL: $rhs is not a valid hex netmask.$!\n" if ($insane and $byte); + }; + }elsif ($rhs =~ qr/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ # /255.255.255.0 form + my @a = ($1, $2, $3, $4); + my $insane = 0; + foreach my $t (@a){ + die "FATAL: Netmask out of range. Input <$rhs> Invalid <$t>$!\n" if (($t < 0) or ($t > 255)); + }; + foreach my $byte (split('', unpack("B32", pack("C4", @a)))){ + ($byte) ? $ucidr++ : $insane++; + die "FATAL: $rhs is not a valid netmask.$!\n" if ($insane and $byte); + }; + }else{ + die "FATAL: Unknown or invalid netmask value entered. <$rhs>\n"; + }; + + # + # Network math GO! This is the meat of the function. + my (@uip) = split(/\./, $uip); + $network = 0; + for ($j = 0; $j <= $#uip; $j++){ + $network += int($uip[$j])<<((3-$j)*8); + }; + + $bits = 0; $j = 0; + for ($j = 31 - $ucidr; $j >= 0; $j--){ + $bits |= 1<<$j; + }; + + $netmask = 0xffffffff^$bits; + $low = ($network&$netmask); + $high = ($network&$netmask)+$bits-1; + $broadcast = ($network&$netmask)|$bits; + my ($guessed_hostname,undef,undef,undef,undef) = gethostbyaddr(inet_aton($uip), AF_INET); + + # + # Throw the info back, they get a hash with zie info they may/may not need. + # All up to the caller what they want to use. + # + return ("inet4" => $uip, + "netmask" => int2ip($netmask), + "broadcast" => int2ip($broadcast), + "cidr" => $ucidr, + "router" => int2ip($low+1), + "network" => int2ip($low), + "high" => int2ip($high), + "hostname" => $guessed_hostname, + ); +}; + +#package Main; # future use + +foreach my $arg (@ARGV){ + my %stuff = cidr2raw($arg); + printf("%s/%s is %s/%s\n%-12s\t%s\n%-12s\t%s\n%-12s\t%s\n%-12s\t%s\n%-12s\t%s\n", + $stuff{"inet4"},$stuff{"cidr"}, + $stuff{"network"},$stuff{"cidr"}, + "Netmask",$stuff{"netmask"}, + "Broadcast",$stuff{"broadcast"}, + "Network",$stuff{"network"}, + "Router",$stuff{"router"}, + "HighUsable",$stuff{"high"}, + ); +}; diff --git a/common/bin/dns b/common/bin/dns new file mode 100755 index 0000000..a04484e --- /dev/null +++ b/common/bin/dns @@ -0,0 +1,36 @@ +#!/usr/bin/env perl +# +# Stupid script to help with dns information. Solaris 9/8 lack the host utility. +# Which this (kinda) mimics, except the mx record crap +use strict; +use warnings; +use Socket; +use Sys::Hostname; + +my $input = shift || hostname(); +my $lookup = $input; + +if ( $lookup =~ /\d+[.]\d+[.]\d+[.]\d+/smx ) { + $lookup = ( gethostbyaddr inet_aton($lookup), AF_INET )[0]; + die "Error: Unable to reverse lookup ip $input.\n" if ( $lookup eq q{} ); +} + +my $ipv4 = gethostbyname $lookup; + +die "Error: $lookup doesn't have any known ip addresses\n" + if ( !defined $ipv4 ); + +$ipv4 = inet_ntoa($ipv4); + +my ( $short_name, $aliases, $addrtype, $len, @addrs ) = gethostbyname $lookup; + +foreach my $ipv4 (@addrs) { + $ipv4 = inet_ntoa($ipv4); + print "$lookup is $ipv4\n"; +} + +print "$lookup is also $short_name\n"; +if ( defined $aliases and "$aliases" ne q{} ) { + print "aliases are ($aliases)\n"; +} +exit 0; diff --git a/common/bin/dups b/common/bin/dups new file mode 100755 index 0000000..aa56109 --- /dev/null +++ b/common/bin/dups @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby +# +# Quick script to find duplicate files +# + +require 'find' +require 'digest/sha1' +require 'set' + +hashes = Hash.new +start = ARGV[0] || ENV["HOME"] +puts "Building digests from #{start}" + +Find.find(start) do |path| + STDOUT.flush + this_hash = Set.new + hash = "NONE" + if (FileTest.directory?(path) or FileTest.symlink?(path)\ + or FileTest.blockdev?(path) or FileTest.chardev?(path)\ + or FileTest.socket?(path) or FileTest.pipe?(path)\ + or FileTest.zero?(path)) then + next + else + begin + file_digest = Digest::SHA1.new + File.open(path, 'r') do |fh| + while buffer = fh.read(8096) + file_digest.update(buffer) + end + end + hash = file_digest.hexdigest + rescue NoMemoryError + puts "NoMemoryError on #{path}" + GC.start + rescue IOError + puts "IOError on #{path}" + GC.start + rescue Errno::ENOSYS; next + rescue Errno::EACCES; next + rescue Errno::EINVAL; next + rescue => e + puts "Unhandled error on #{path}, exception #{e}" + p e + exit 255 + end + end + if (hashes[hash]) then + hashes[hash].add(path) + else + hashes[hash] = this_hash.add(path) + end +end + +puts "Digest generation complete." +hashes.each_pair do |key, val| + files = val.to_a + files.delete(nil) + files.delete_if {|x| "#{x}" =~ /^\s*$/} + next if (files.size < 2) + puts "Duplicate digest <#{key}> for files:\n #{files.join("\n ")}" +end diff --git a/common/bin/emptydirs b/common/bin/emptydirs new file mode 100755 index 0000000..1822fe7 --- /dev/null +++ b/common/bin/emptydirs @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +# +# Because all find implementations, that is, everything but gnu find. +# lack -find as an option. +# + +use File::Find; + +my $debug; +(exists($ENV{"DEBUG"})) ? $debug++ : undef; +my $dir = $ARGV[-1] || '/tmp'; + + +find(\&sieve, $dir); + +sub sieve { + my $file = $File::Find::name; + my $filedir = $File::Find::dir; + my ($dev,$inode,undef,undef,undef,undef,undef,$size) = lstat($file); + next if !(-d $file); # Only zie diectories BITTE! + # + # Ok, lets see if readdir returns more than 2 entries. + opendir my $H, $file or next; + print "$file\n" unless (grep !/^\.{1,2}/, readdir $H); + close $H; +}; diff --git a/common/bin/gecos b/common/bin/gecos new file mode 100755 index 0000000..ac082d0 --- /dev/null +++ b/common/bin/gecos @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# +# Dumb wrapper to get the gecos information from a uid/username. + +foreach my $input (@ARGV){ + my $gecos = undef; + my $uid = undef; + my $name = undef; + if ( $input =~ m/^\d+$/ ) { + ( $name,$uid,$gecos ) = ( getpwuid($input) )[0,2,6]; + } else { + ( $name,$uid,$gecos ) = ( getpwnam($input) )[0,2,6]; + } + print "$name is '$gecos' uid '$uid'\n" if $gecos; +} diff --git a/common/bin/hatimerun b/common/bin/hatimerun new file mode 100755 index 0000000..2eaa079 --- /dev/null +++ b/common/bin/hatimerun @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +# +# hatimerun in perl, sorta +# +use Getopt::Long; + +my $opt_exitcode = 99; +my $opt_killcode = 9; +my $opt_timeout = 60; + +GetOptions( 'e=i' => \$opt_exitcode, + 'k=i' => \$opt_killcode, + 't=i' => \$opt_timeout, + 'h' => \&opt_help, + 'help' => \&opt_help, +); + +sub opt_help{ + my $message = <<__END__; +UX: ERROR: invalid syntax +usage: [-e return code][-k kill signal][-t seconds to wait] + [-h][--help] + + Options + --help, -h Prints this help text. + -e Exit code to return on timeout. + NOTE: 99 by default. + -k Signal number to send via kill. + NOTE: 9 by default. + -t Timeout in seconds before alarming. + NOTE: 60 by default. + +__END__ + print $message; + exit 1; +}; + +my $pid; + +local $SIG{ALRM} = sub { kill $opt_killcode, $pid or die "Kill failed: $!"; + die "Timeout!\n"}; + +eval{ + my $x = defined($pid = fork()); + + unless ($pid){ + print qx(@ARGV); + die "Exec of ", join(' ', @ARGV), " failed at $!\n"; + }; + + alarm $opt_timeout; + waitpid $pid => 0; + alarm 0; + exit 0; +}; + +if ($@){ + die "Nothing to do!\n" unless $@ eq "Timeout!\n"; + exit $opt_exitcode; +}else{ + exit 0; +}; diff --git a/common/bin/ifinfo b/common/bin/ifinfo new file mode 100755 index 0000000..02bc0d6 --- /dev/null +++ b/common/bin/ifinfo @@ -0,0 +1,209 @@ +#!/usr/bin/env perl +# +# Because ifconfig output is... overly verbose. +# +# Output information from ifconfig -a like so: +# interface:mtu ipv4/cidr mac_address ipv6_addr(if applicable) +# ipv6 is not yet in place due to a: lazy, b: can't use it yet. +# + +use strict; +use Socket; +use Sys::Hostname; +$ENV{'PATH'}='/sbin:/usr/sbin:/bin:/usr/bin'; + +my ($fqdn_regexp) = qr/([0-9,a-z,A-Z,\-,\_]+)\.([0-9,a-z,A-Z,\-,\_]+)\.(com|gov)/; + +# +# converts a 1-word (4 byte) signed or unsigned integer into a dotted decimal +# ip address. +# +sub int2ip { + my $n=int(pop); + return(sprintf("%d.%d.%d.%d", ($n>>24)&0xff,($n>>16)&0xff, + ($n>>8)&0xff,$n&0xff)); +}; + +# +# Convert a host/ip/netmask/cidr/etc.... to a hash of information +# Example: host.domain.tld/24 will get the ip and calculate the netmask info +# equally if host.domain.tld corresponds with 1.2.3.4 the following is valid +# 1.2.3.4/255.255.255.0 would obtain the same information. +# +# die()'s if anything isn't kosher. +# +# Ultra long function, probably needs to be looked at for condensing/splitting. +# +sub cidr2raw { + my $rawinput = pop; + my ($lhs, $rhs, $j, $uip) = (undef, undef, undef, undef); + my ($ucidr) = 0; + my ($network, $bits, $netmask, $broadcast, $low, $high); + + if ($rawinput =~ qr/(.*)\/(.*)/){ + $lhs = $1; $rhs = $2; + }else{ + die "Input: $rawinput not expected.\n"; + }; + + # + # Handle ip/hostname for left hand side. + if ($lhs =~ qr/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ + foreach my $dotted (($1,$2,$3,$4)){ + if (($dotted > 255) or ($dotted < 0)){ + die "FATAL: ipv4 address entered, $lhs entered is impossible, $dotted is not between 0-255.\n"; + }; + }; + $uip = "$1.$2.$3.$4"; + }; + # + # Handle the netmask/cidr for the right hand side, + # + # All input netmasks are converted to a cidr address for notation + if ($rhs =~ qr/^(\d+)$/){ # /cidr + $ucidr = $1; + die "FATAL: Invalid CIDR <$ucidr>.$!\n" if (($ucidr > 32) or ($ucidr < 0)); + }elsif ($rhs =~ qr/(0[xX])?([0-9,a-f,A-F]{7})/){ # /0xhexnetmask + my $trimmed = $2; + my $insane = 0; + foreach my $byte (split('', unpack("B32", pack("H*", $trimmed)))){ + ($byte) ? $ucidr++ : $insane++; + die "FATAL: $rhs is not a valid hex netmask.$!\n" if ($insane and $byte); + }; + }elsif ($rhs =~ qr/(\d+)\.(\d+)\.(\d+)\.(\d+)/){ # /255.255.255.0 form + my @a = ($1, $2, $3, $4); + my $insane = 0; + foreach my $t (@a){ + die "FATAL: Netmask out of range. Input <$rhs> Invalid <$t>$!\n" if (($t < 0) or ($t > 255)); + }; + foreach my $byte (split('', unpack("B32", pack("C4", @a)))){ + ($byte) ? $ucidr++ : $insane++; + die "FATAL: $rhs is not a valid netmask.$!\n" if ($insane and $byte); + }; + }else{ + die "FATAL: Unknown or invalid netmask value entered. <$rhs>\n"; + }; + + # + # Network math GO! This is the meat of the function. + my (@uip) = split(/\./, $uip); + $network = 0; + for ($j = 0; $j <= $#uip; $j++){ + $network += int($uip[$j])<<((3-$j)*8); + }; + + $bits = 0; $j = 0; + for ($j = 31 - $ucidr; $j >= 0; $j--){ + $bits |= 1<<$j; + }; + + $netmask = 0xffffffff^$bits; + $low = ($network&$netmask); + $high = ($network&$netmask)+$bits-1; + $broadcast = ($network&$netmask)|$bits; + + # + # Throw the info back, they get a hash with zie info they may/may not need. + # All up to the caller what they want to use. + # + return ("inet4" => $uip, + "netmask" => int2ip($netmask), + "broadcast" => int2ip($broadcast), + "cidr" => $ucidr, + "router" => int2ip($low+1), + "network" => int2ip($low), + "high" => int2ip($high), + ); +}; + +my @ifout; +if ($ENV{'TESTING'} ne '') { + while(<>){ + chomp($_); + last if ($_ eq ''); + push(@ifout, $_); +# sleep 1; +# print STDERR $_ . "\n"; + } +}else{ + open IFCONFIG, "ifconfig -a |"; + @ifout = ; + close IFCONFIG; +} + +# This seems wrong but it makes parsing easier due to solaris +# non root ifconfig not displaying the mac address. Reverse the output. +# +@ifout = reverse(@ifout); + +my @output = (); + +my ($ifname, $ifether, $ifmtu, $ifipv4, $ifnetmask, $ifipv6) = (undef,undef,undef,undef,undef,undef); +sub printiface{ + # assume a /32 if we don't know it + unless (defined($ifnetmask)) { + warn "$ifname has indeterminant netmask assuming /32\n"; + $ifnetmask = '32'; + } + + unless (defined($ifnetmask)) { + $ifether = 'unknown'; + } + + unless ($ifname =~ m/lo.*/){ + my %netinfo = cidr2raw("$ifipv4\/$ifnetmask"); + $ifnetmask = $netinfo{"cidr"}; + $ifether = lc($ifether); + my $line = sprintf "%-16s %-18s %-17s\n", "$ifname\@$ifmtu", "$ifipv4\/$ifnetmask", $ifether; + push @output, $line; + } + + # reset vars + ($ifname, $ifether, $ifmtu, $ifipv4, $ifnetmask, $ifipv6) = (undef,undef,undef,undef,undef,undef); +}; + +foreach my $line (@ifout) { + if ($line =~ /inet\s+(\d+[.]\d+[.]\d+[.]\d+)\s+/){ + $ifipv4 = $1; + } + if ($line =~ m/ether\s([:,0-9,a-f,A-F]{11,})/){ + $ifether =$1; + } + if ($line =~ m/^([\w,\:\d+]+)\s+.*HWaddr\s([:,0-9,a-f,A-F]{11,})/){ + $ifname = $1; + $ifether = $2; + } + if ($line =~ m/^(.*)\:\s+.*mtu\s(\d+)/){ + $ifname = $1; + $ifmtu = $2; + } + if ($line =~ m/MTU[:](\d+)/){ + $ifmtu = $1; + } + if ($line =~ m/inet\saddr\:(\d+[.]\d+[.]\d+[.]\d+)/){ + $ifipv4 = $1; + } + if ($line =~ m/netmask\s+(0[xX])?([a-f,A-F,0-9]{8})/){ + $ifnetmask = $2; + } + if ($line =~ m/Mask[:](\d+\.\d+\.\d+\.\d+)/){ + $ifnetmask = $1; + } + if ($line =~ m/netmask\s+(\d+[.]\d+[.]\d+[.]\d+)/){ + $ifnetmask = $1; + } + if ($line =~ m/netmask\s+0\s+broadcast/){ + $ifnetmask = '0'; + } + + print ":$ifether:$ifname:$ifmtu:$ifipv4:$ifnetmask:$ifipv6:\n" if ($ENV{'DEBUG'} ne ''); + printiface() if ($ifname and $ifmtu and $ifipv4 ); +}; + +if (scalar(@output) < 1){ + warn "No interfaces? Scripts busted yo.\n"; +}else{ + foreach my $line (reverse(@output)){ + print $line; + } +} diff --git a/common/bin/iso8601 b/common/bin/iso8601 new file mode 100755 index 0000000..5a5515b --- /dev/null +++ b/common/bin/iso8601 @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +#-*-mode: Perl; coding: utf-8;-*- +use strict; +use warnings; +use POSIX qw(strftime); + +my $now = time; +my $local_now = localtime $now; +my $tz = strftime '%z', $local_now; +$tz =~ s/(\d{2})(\d{2})/$1:$2/smx; +my $time = strftime '%Y-%m-%dT%H:%M:%S', $local_now; +print "$time$tz\n"; +exit 0; diff --git a/common/bin/portchk b/common/bin/portchk new file mode 100755 index 0000000..d4eeb5b --- /dev/null +++ b/common/bin/portchk @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# +# Just opens a socket and tries to connect() to it. rc = 1 on failure, 0 success +# +use Socket; + +local $where = $ARGV[0]; +local $port = $ARGV[1]; + +socket(SOCKET,PF_INET,SOCK_STREAM,(getprotobyname("tcp"))[2]); + +if(connect(SOCKET,sockaddr_in($port,inet_aton($where)))){ + print "connect($where, $port) succeeded\n"; + exit 0; +}else{ + print "connect($where, $port) failed\n"; + exit 1; +}; diff --git a/common/bin/ptree.pl b/common/bin/ptree.pl new file mode 100755 index 0000000..d02733d --- /dev/null +++ b/common/bin/ptree.pl @@ -0,0 +1,171 @@ +#!/usr/bin/env perl +# +# ptree for linux/darwin/solaris. I got sick of ps and pstree on linux. +# ptree works on solaris fine, but doesn't exist for darwin/linux/etc... +# +# TODO: Allow passing a regexp instead of a pid and passing multiple pids. +# + +local $ENV{"PATH"} = '/bin:/usr/bin:/sbin:/usr/sbin'; +local $debug = 0; + +(exists($ENV{"DEBUG"})) ? $debug = 1 : undef; +($debug) ? local $| = 1 : undef; # disable buffering for STDERR and STDOUT + +sub debug_print { + ($debug) && warn pop; +}; + +local @cmd = ('/bin/ps'); +local $init = 0; +local $start = 1; + +if ($^O eq "linux"){ + push(@cmd, 'ajxSw'); + $start = 0; +}elsif ($^O =~ m/darwin|freebsd/){ + push(@cmd, 'Ajwww'); +}elsif ($^O eq "solaris"){ + @cmd = ('/usr/ucb/ps'); + if ((-x "/bin/zonename") && !(qx(zonename) eq "global\n")){ + $init = qx(pgrep zsched); + chomp($init); + $start = $init; + }; + push(@cmd, 'laxwww'); +}else{ + die "$^O isn't a known os to this script\n"; +}; + +local @ps = qx(@cmd); +($?) ? die $cmd[0]." posix return code $?\n" : undef; + +local %proc; +local @trail; + +(defined($ARGV[0])) ? $start = $ARGV[0] : undef; + +debug_print("Dump of raw line array data:\n"); + +foreach my $x (@ps){ + my $cmd_index = 9; + my $ppid = -1; + my $pid = -1; + next if ($x =~ m/.*PID.*/); + my @line = split(m/\s+/,$x); + splice(@line, 0, 1) unless ($line[0] =~ m/\d+/); + splice(@line, 0, 1) if ("$line[0]" eq ""); + + if ($^O eq "linux"){ + ($ppid,$pid) = @line; + $cmd_index = 9; + }elsif ($^O =~ m/darwin|freebsd/){ + ($pid,$ppid) = @line; + $cmd_index = 8; + }elsif ($^O eq "solaris"){ + (undef, undef, $pid,$ppid) = @line; + for($x=$cmd_index; $x < 14; $x++){ + $cmd_index = ($line[$x] =~ m/\d+\:\d+/) ? ($x + 1) : $cmd_index; + }; + }; + + my $command = join(' ', @line[$cmd_index..$#line++]); + (!defined $proc{$pid}) ? $proc{$pid}->{"children"} = [ ] : undef; + (!defined $proc{$ppid}) ? $proc{$ppid}->{"children"} = [ ] : undef; + $proc{$pid}->{"pid"} = $pid; + $proc{$pid}->{"command"} = $command; + $proc{$pid}->{"ppid"} = $ppid; + push(@{$proc{$ppid}->{"children"}},$pid); + debug_print(join(',', @line[0..($#line-1)])."\n"); +}; + +if ($debug){ + debug_print("Done reading ps output\nDump of Hash\n"); + foreach my $key (sort({$a <=> $b} (keys %proc))){ + $ppid = $proc{$key}->{"ppid"}; + $command = $proc{$key}->{"command"}; + $children = join(',', @{$proc{$key}->{"children"}}); + debug_print("PID<$key> PPID<$ppid> Children<$children> Command<$command>\n"); + }; +}; + +sub intrail{ + my $crumb = pop; + my $ret = 0; + map {$ret++ if ($crumb == $_)} @trail; + return $ret; +}; + +sub addchildren{ + my $start_node = pop; + foreach my $child (@{$proc{$start_node}->{"children"}}){ + next if (!defined($child) || ($start_node == $child)); + debug_print("Start ($start_node) Add child $child.\n"); + push(@trail, $child); + addchildren($child); + }; +}; + +sub addparents{ + my $start_node = pop; + my $parent = $proc{$start_node}->{"ppid"}; + return unless (defined($start_node)); + return if (($parent == $start_node) || !(defined($parent))); # At the top of the tree, or in a zone + debug_print("Start ($start_node) Add parent $parent.\n"); + push(@trail, $parent); + addparents($parent) if ($parent != $init); +}; + +sub printnode{ + my $start_node = pop; + my $indent = pop; + if (intrail($start_node)){ + my $pid = $proc{$start_node}->{"pid"}; + my $ppid = $proc{$start_node}->{"ppid"}; + my $cmdline = $proc{$start_node}->{"command"}; + my $indentation = ' 'x($indent); + if ($pid == $init){ + my $s = $^O." kernel"; + if ($cmdline ne ''){ + $s = $s." <$cmdline>"; + }; + $cmdline = $s; + }; + printf("%s%d %s\n", $indentation, $pid, $cmdline); + foreach my $child (@{$proc{$start_node}->{"children"}}){ + next if ($pid == $child); + printnode($indent+1,$child); + }; + }; +}; + +my $valid = 0; +foreach my $j (keys %proc){ ($j == $start) ? $valid++ : undef; }; + +debug_print("Starting from <$start>, validity is<$valid>\n"); + +if ($valid){ + if (!$start){ + @trail = keys %proc; + push(@trail, $start); push(@trail, 1); + debug_print("Done with adding $start to trail.\n"); + }else{ + push(@trail, $start); + debug_print("Adding children from $start.\n"); + addchildren($start); + debug_print("Adding parents from $start.\n"); + addparents($start); + }; + + @trail = sort(@trail); + + debug_print("Trail is: ".join(',', @trail)."\nStarting at pid $start\ninit pid $init\n"); + print "PID COMMAND\n"; + my $startindent = 0; + (intrail($startindent)) ? $startindent = -1 : undef; + printnode($startindent,$init); +}else{ + die "pid $start doesn't exist.\n"; +}; + +exit 0; diff --git a/common/bin/today b/common/bin/today new file mode 100755 index 0000000..e2e9636 --- /dev/null +++ b/common/bin/today @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby +# + +cal, today, week_color, day_color, reset = %x(cal).split(%r(\n)), Time.now.day, %x(tput sgr0;tput setab 4;tput setaf 7), %x(tput sgr0; tput setab 0;tput setaf 7;tput bold), %x(tput sgr0) +done=false +cal.each do |line| + if done then + puts line + next + end + if(line =~ /^(.*\s+?)#{today}(\s+?.*)$/ or + line =~ /^(.*\s+?)#{today}$/ or + line =~ /^()#{today}(\s+?.*)$/ or + line =~ /^#{today}$/ ) then + puts "#{week_color}#{$1}#{day_color}#{today}#{week_color}#{$2}#{reset}" + done=true + else + puts line + end +end diff --git a/common/bin/ts b/common/bin/ts new file mode 100755 index 0000000..36036dd --- /dev/null +++ b/common/bin/ts @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# +# Timestamp stdin and then print to stdout and flush. +# +# Thats about it. Might add a quick and dirty option to allow you to +# specify the time output whatnot. But this is intended to be simple. +# + +while(){ + print localtime()." : ".$_; + $stdout.flush; +}; diff --git a/common/bin/whoson b/common/bin/whoson new file mode 100755 index 0000000..89ea1f5 --- /dev/null +++ b/common/bin/whoson @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +# +# Because i'm lazy and sick of typing in getent passwd $someusername/uid +# + +my %who_cmds = ("solaris", "/bin/who -q", + "linux", "/usr/bin/who -q", + "darwin", "/usr/bin/who -q", + ); + +my $who_cmd = $who_cmds{$^O}; + +local %users = (); + +foreach my $l (qx/$who_cmd/){ + next if($l =~ m/^\#.*/); + foreach my $user (split(/\s+/,$l)){ + unless(exists($users{$user})){ + $users{$user} = 0; + }else{ + $users{$user}++; + }; + }; +}; + +foreach my $user (keys %users){ + my $gecos = ( getpwnam($user) )[6]; + my $count = $users{$user} + 1; + my $output = "$user\, ".((defined($gecos)) ? "$gecos, " : '')."is logged in on $count tty".(($count>1) ? "\'s" : '')."\n"; + print $output; +}; diff --git a/emacs/.emacs.d/.gitignore b/emacs/.emacs.d/.gitignore new file mode 100644 index 0000000..58362c4 --- /dev/null +++ b/emacs/.emacs.d/.gitignore @@ -0,0 +1,7 @@ +session* +elpa +tramp +url +ac-dict +ac-comphist.dat +.emacs.desktop* diff --git a/emacs/.emacs.d/after-init.el b/emacs/.emacs.d/after-init.el new file mode 100644 index 0000000..6c4bb2c --- /dev/null +++ b/emacs/.emacs.d/after-init.el @@ -0,0 +1,12 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(require 'haskell-mode) +(require 'haskell-process) +(require 'haskell-simple-indent) +(require 'haskell-interactive-mode) +(require 'haskell-font-lock) +(require 'haskell-debug) +(require 'sgml-mode) +(require 'css-mode) +(require 'helm-config) +(helm-mode 1) +(color-theme-solarized-light) diff --git a/emacs/.emacs.d/emacs-package.el b/emacs/.emacs.d/emacs-package.el new file mode 100644 index 0000000..110f021 --- /dev/null +++ b/emacs/.emacs.d/emacs-package.el @@ -0,0 +1,68 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(require 'package) +(setq my-packages + '( + helm + dash + s + string-utils + list-utils + flycheck + expand-region + auto-complete + auto-complete-clang-async + magit + smex + column-marker + ruby-end + multi-term + dropdown-list + popup + org-plus-contrib + org-bullets + org-pomodoro + org-present + color-theme + perl-completion + workgroups + yasnippet + figlet + org-readme + move-text + smartparens + markdown-mode + yaml-mode + go-mode + rust-mode + haskell-mode + color-theme-solarized + )) + +(package-initialize) + +(add-to-list 'package-archives + '("melpa" . "http://melpa.milkbox.net/packages/")) +(add-to-list 'package-archives + '("gnu" . "http://elpa.gnu.org/packages/")) +(add-to-list 'package-archives + '("org" . "http://orgmode.org/elpa/")) + +;; TODO: maybe set an ENV var to force refresh at startup? +(when (not package-archive-contents) + (package-refresh-contents)) + +(dolist (pkg my-packages) + (when (and (not (package-installed-p pkg)) + (assoc pkg package-archive-contents)) + (package-install pkg))) + +(defun package-list-unaccounted-packages () + "Like `package-list-packages', but shows only the packages that + are installed and are not in `my-packages'. Useful for + cleaning out unwanted packages." + (interactive) + (package-show-package-list + (remove-if-not (lambda (x) (and (not (memq x my-packages)) + (not (package-built-in-p x)) + (package-installed-p x))) + (mapcar 'car package-archive-contents)))) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el new file mode 100644 index 0000000..c1945ca --- /dev/null +++ b/emacs/.emacs.d/init.el @@ -0,0 +1,66 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +;; In case I screw up something later, debug stuff +(setq debug-on-error t) + +;; Simplify os detection a skosh +(defvar mswindows-p (string-match "windows" (symbol-name system-type)) + "Am I running under windows?") +(defvar osx-p (string-match "darwin" (symbol-name system-type)) + "Am I running under osx?") +(defvar linux-p (string-match "gnu/linux" (symbol-name system-type)) + "Am I running under linux?") + +;; Yes, I miss perl chomp, sue me +(defun chomp (str) + "Chomp leading and trailing whitespace from STR." + (let ((s (if (symbolp str) (symbol-name str) str))) + (replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" "" s))) + +;; I'm not about to redo logic to setup PATH in emacs that I have in +;; .profile/.*shrc crap. +;; So, just use whatever PATH had when we were run. +(defun set-exec-path-from-shell-PATH () + (let ((path-from-shell + (shell-command-to-string "$SHELL -i -c 'echo $PATH'"))) + (setenv "PATH" path-from-shell) + (setq exec-path (split-string path-from-shell path-separator)))) + +;; This is really only needed when the gui emacs runs. +(if osx-p + (set-exec-path-from-shell-PATH) + ) + +;; Base directory +(defvar load-base "~/.emacs.d" "Where the emacs directory is kept") + +;; Bootstrap load path +(add-to-list 'load-path load-base) + +;; Temp file dir (unixes) +(setq temporary-file-directory "/tmp") + +;; Set the default temp file dir for the current user based off username +(defvar user-temporary-file-directory + (format "%s/%s" temporary-file-directory user-login-name)) + +;; mkdir for temporary-file-directory if needed +(unless (file-accessible-directory-p user-temporary-file-directory) + (make-directory user-temporary-file-directory t)) + +;; Load up settings of things, in no particular order or anything +(mapcar 'load-file (directory-files "~/.emacs.d/settings/" t ".*.el$")) + +;; Setup/install third party packages using builtin package manager. +(load "emacs-package") + +;; Load up settings for things that el-get installed +(mapcar 'load-file (directory-files "~/.emacs.d/package-settings/" t ".*.el$")) + +;; Cleanup startup buffers +(add-hook 'after-init-hook + '(lambda () (load "after-init"))) + +;; Fine, emacsclient -c and emacs --daemon don't mix well +;; From now on I start emacs as a gui and have this startup the daemon +(load "server") +(unless (server-running-p) (server-start)) diff --git a/emacs/.emacs.d/misc/clang-format.el b/emacs/.emacs.d/misc/clang-format.el new file mode 100644 index 0000000..520a3e2 --- /dev/null +++ b/emacs/.emacs.d/misc/clang-format.el @@ -0,0 +1,56 @@ +;;; Clang-format emacs integration for use with C/Objective-C/C++. + +;; This defines a function clang-format-region that you can bind to a key. +;; A minimal .emacs would contain: +;; +;; (load "/tools/clang-format/clang-format.el") +;; (global-set-key [C-M-tab] 'clang-format-region) +;; +;; Depending on your configuration and coding style, you might need to modify +;; 'style' in clang-format, below. + +(require 'json) + +;; *Location of the clang-format binary. If it is on your PATH, a full path name +;; need not be specified. +(defvar clang-format-binary "clang-format") + +(defun clang-format-region () + "Use clang-format to format the currently active region." + (interactive) + (let ((beg (if mark-active + (region-beginning) + (min (line-beginning-position) (1- (point-max))))) + (end (if mark-active + (region-end) + (line-end-position)))) + (clang-format beg end))) + +(defun clang-format-buffer () + "Use clang-format to format the current buffer." + (interactive) + (clang-format (point-min) (point-max))) + +(defun clang-format (begin end) + "Use clang-format to format the code between BEGIN and END." + (let* ((orig-windows (get-buffer-window-list (current-buffer))) + (orig-window-starts (mapcar #'window-start orig-windows)) + (orig-point (point)) + (style "file")) + (unwind-protect + (call-process-region (point-min) (point-max) clang-format-binary + t (list t nil) nil + "-offset" (number-to-string (1- begin)) + "-length" (number-to-string (- end begin)) + "-cursor" (number-to-string (1- (point))) + "-assume-filename" (buffer-file-name) + "-style" style) + (goto-char (point-min)) + (let ((json-output (json-read-from-string + (buffer-substring-no-properties + (point-min) (line-beginning-position 2))))) + (delete-region (point-min) (line-beginning-position 2)) + (goto-char (1+ (cdr (assoc 'Cursor json-output)))) + (dotimes (index (length orig-windows)) + (set-window-start (nth index orig-windows) + (nth index orig-window-starts))))))) diff --git a/emacs/.emacs.d/mode-defaults.el b/emacs/.emacs.d/mode-defaults.el new file mode 100644 index 0000000..833afb8 --- /dev/null +++ b/emacs/.emacs.d/mode-defaults.el @@ -0,0 +1,7 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(auto-complete-mode) +(whitespace-mode) +(smartparens-mode) +(visual-line-mode) +(setq indent-tabs-mode nil) +(setq tab-width 2) diff --git a/emacs/.emacs.d/modes/cc.el b/emacs/.emacs.d/modes/cc.el new file mode 100644 index 0000000..ee7ac15 --- /dev/null +++ b/emacs/.emacs.d/modes/cc.el @@ -0,0 +1,28 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(add-to-list 'auto-mode-alist '("\\.[chm]\\'" . c-mode)) + +(add-hook 'c-mode-common-hook + '(lambda () + (global-set-key "\C-x\C-m" 'compile) + ;; c11 is best standard, silly c++11. + (setq flycheck-clang-language-standard "c11") + ;; Wait a bit for me to type things out guy. + (setq flycheck-idle-change-delay 2) + (setq flycheck-highlighting-mode 'symbols) + (add-hook 'before-save-hook 'clang-format-buffer nil t) + (auto-complete-mode) + (whitespace-mode) + (hl-line-mode) + (visual-line-mode) + (smartparens-mode) + (flycheck-mode) + (c-toggle-auto-state 1) + (setq-default c-basic-offset 2 + tab-width 2 + indent-tabs-mode nil + c-electric-flag t + indent-level 2 + c-default-style "bsd" + backward-delete-function nil) + )) diff --git a/emacs/.emacs.d/modes/elisp.el b/emacs/.emacs.d/modes/elisp.el new file mode 100644 index 0000000..1eecb4f --- /dev/null +++ b/emacs/.emacs.d/modes/elisp.el @@ -0,0 +1,15 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(add-to-list 'auto-mode-alist '("\\.el" . emacs-lisp-mode)) + +(add-hook 'emacs-lisp-hook + (lambda () + (hl-line-mode) + (whitespace-mode) + (flycheck-mode) + (setq-default tab-width 2) + (setq-default indent-tabs-mode nil) + (define-key emacs-lisp-map + "\C-x\C-e" 'pp-eval-last-sexp) + (define-key emacs-lisp-map + "\r" 'reindent-then-newline-and-indent))) diff --git a/emacs/.emacs.d/modes/go.el b/emacs/.emacs.d/modes/go.el new file mode 100644 index 0000000..70b8272 --- /dev/null +++ b/emacs/.emacs.d/modes/go.el @@ -0,0 +1,11 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(add-hook 'go-mode-hook '(lambda () + (add-hook 'before-save-hook #'gofmt-before-save) + (smartparens-mode) + (auto-complete-mode) + (hl-line-mode) + (visual-line-mode) + (whitespace-mode) + (setq tab-width 8) + )) diff --git a/emacs/.emacs.d/modes/haskell.el b/emacs/.emacs.d/modes/haskell.el new file mode 100644 index 0000000..611dac1 --- /dev/null +++ b/emacs/.emacs.d/modes/haskell.el @@ -0,0 +1,89 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(custom-set-variables + '(haskell-process-type 'ghci) + '(haskell-process-args-ghci '()) + '(haskell-notify-p t) + '(haskell-stylish-on-save nil) + '(haskell-tags-on-save t) + '(haskell-process-suggest-remove-import-lines t) + '(haskell-process-auto-import-loaded-modules t) + '(haskell-process-log t) + '(haskell-process-reload-with-fbytecode nil) + '(haskell-process-use-presentation-mode t) + '(haskell-interactive-mode-include-file-name nil) + '(haskell-interactive-mode-eval-pretty nil) +;; '(shm-use-hdevtools t) +;; '(shm-use-presentation-mode t) +;; '(shm-auto-insert-skeletons t) +;; '(shm-auto-insert-bangs t) + '(haskell-process-show-debug-tips nil) + '(haskell-process-suggest-hoogle-imports nil) + '(haskell-process-suggest-haskell-docs-imports t)) + +(setq haskell-complete-module-preferred + '("Data.ByteString" + "Data.ByteString.Lazy" + "Data.Function" + "Data.List" + "Data.Map" + "Data.Maybe" + "Data.Monoid" + "Data.Ord")) + +(autoload 'ghc-init "ghc" nil t) +(autoload 'ghc-debug "ghc" nil t) + +(add-hook + 'haskell-mode-hook + '(lambda () + (ghc-init) + (setq haskell-interactive-mode-eval-mode 'haskell-mode) + '(turn-on-haskell-indentation) + (interactive-haskell-mode) + (custom-set-variables + '(haskell-process-suggest-remove-import-lines t) + '(haskell-process-auto-import-loaded-modules t) + '(haskell-process-log t) + '(haskell-tags-on-save t) + '(haskell-process-type 'cabal-repl) + ) + (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload) + (define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring) + (define-key haskell-mode-map (kbd "C-c C-n C-t") 'haskell-process-do-type) + (define-key haskell-mode-map (kbd "C-c C-n C-i") 'haskell-process-do-info) + (define-key haskell-mode-map (kbd "C-c C-n C-c") 'haskell-process-cabal-build) + (define-key haskell-mode-map (kbd "C-c C-n c") 'haskell-process-cabal) + (define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space) + (define-key haskell-mode-map (kbd "M-.") 'haskell-mode-jump-to-def-or-tag) + (define-key haskell-mode-map [f8] 'haskell-navigate-imports) + ) + ) + +(add-hook 'cabal-mode-hook (lambda () + (define-key haskell-cabal-mode-map (kbd "C-`") 'haskell-interactive-bring) + (define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-ode-clear) + (define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build) + (define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal))) +;; (stylish-haskell-mode) +;; (define-key haskell-mode-map +;; (kbd "C-x C-s") 'haskell-mode-save-buffer) +;; (add-to-list 'align-rules-list +;; '(haskell-types +;; (regexp . "\\(\\s-+\\)\\(::\\|∷\\)\\s-+") +;; (modes quote (haskell-mode literate-haskell-mode)))) +;; (add-to-list 'align-rules-list +;; '(haskell-assignment +;; (regexp . "\\(\\s-+\\)=\\s-+") +;; (modes quote (haskell-mode literate-haskell-mode)))) +;; (add-to-list 'align-rules-list +;; '(haskell-arrows +;; (regexp . "\\(\\s-+\\)\\(->\\|→\\)\\s-+") +;; (modes quote (haskell-mode literate-haskell-mode)))) +;; (add-to-list 'align-rules-list +;; '(haskell-left-arrows +;; (regexp . "\\(\\s-+\\)\\(<-\\|←\\)\\s-+") +;; (modes quote (haskell-mode literate-haskell-mode)))) +;; )) + +;; MOVE ME +(global-set-key (kbd "C-x a r") 'align-regexp) diff --git a/emacs/.emacs.d/modes/makefile.el b/emacs/.emacs.d/modes/makefile.el new file mode 100644 index 0000000..555f320 --- /dev/null +++ b/emacs/.emacs.d/modes/makefile.el @@ -0,0 +1,14 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(autoload 'makefile-mode "makefile-mode" "mode for makefile stuff" t) + +(add-to-list 'auto-mode-alist '("\\.[Mm]akefile\\'" . makefile-mode)) +(add-to-list 'auto-mode-alist '("\\.GNUMakefile\\'" . makefile-mode)) + +(add-hook 'makefile-mode-hook + '(lambda () + (hl-line-mode) + (smartparens-mode) + (whitespace-mode) + (visual-line-mode) + (setq tab-width 4))) diff --git a/emacs/.emacs.d/modes/org.el b/emacs/.emacs.d/modes/org.el new file mode 100644 index 0000000..ebcdfbd --- /dev/null +++ b/emacs/.emacs.d/modes/org.el @@ -0,0 +1,14 @@ +;;-*-mode: Emacs-Lisp; coding: utf-8;-*- + +(add-to-list 'auto-mode-alist '("\\.org\>" . org-mode)) + +(add-hook 'org-mode-hook + (lambda () + (ispell-minor-mode) + (visual-line-mode) + (hl-line-mode) + (delete '("\\.pdf\\'" . default) org-file-apps) + (if osx-p + (add-to-list 'org-file-apps '("\\.pdf\\'" . "open %s")) + (add-to-list 'org-file-apps '("\\.pdf\\'" . "evince %s"))) + )) diff --git a/emacs/.emacs.d/modes/perl.el b/emacs/.emacs.d/modes/perl.el new file mode 100644 index 0000000..6c5bb20 --- /dev/null +++ b/emacs/.emacs.d/modes/perl.el @@ -0,0 +1,12 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(autoload 'cperl-mode "cperl-mode" "mode for perl scripts" t) + +(add-to-list 'auto-mode-alist '("\\.[Pp][LlMm]\\'" . cperl-mode)) + +(add-hook 'cperl-mode-hook + '(lambda () + (load "mode-defaults") + (smartparens-mode) + (flycheck-mode) + )) diff --git a/emacs/.emacs.d/modes/python.el b/emacs/.emacs.d/modes/python.el new file mode 100644 index 0000000..813aa4e --- /dev/null +++ b/emacs/.emacs.d/modes/python.el @@ -0,0 +1,9 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(add-hook 'python-mode-hook + '(lambda () + (load "mode-defaults") + (smartparens-mode) + (flycheck-mode) + (flycheck-select-checker 'python-flake8) + )) diff --git a/emacs/.emacs.d/modes/ruby.el b/emacs/.emacs.d/modes/ruby.el new file mode 100644 index 0000000..6074cf6 --- /dev/null +++ b/emacs/.emacs.d/modes/ruby.el @@ -0,0 +1,18 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(autoload 'ruby-mode "ruby-mode" "mode for Ruby formatted stuff" t) + +(add-to-list 'auto-mode-alist '("\\.rb\\'" . ruby-mode)) +(add-to-list 'auto-mode-alist '("\\.rake\\'" . ruby-mode)) +(add-to-list 'auto-mode-alist '("\\.gemspec\\'" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Gemfile\\'" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Rakefile\\'" . ruby-mode)) +(add-to-list 'auto-mode-alist '("Vagrantfile\\'" . ruby-mode)) + +(add-hook 'ruby-mode-hook + '(lambda () + (load "mode-defaults") + (smartparens-mode) + (ruby-end-mode) + (flycheck-mode) + )) diff --git a/emacs/.emacs.d/modes/rust.el b/emacs/.emacs.d/modes/rust.el new file mode 100644 index 0000000..60fd002 --- /dev/null +++ b/emacs/.emacs.d/modes/rust.el @@ -0,0 +1,33 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(add-hook 'rust-mode-hook '(lambda () (interactive) (column-marker-1 80))) +(add-hook 'rust-mode-hook '(lambda () + (smartparens-mode) + (auto-complete-mode) + (hl-line-mode) + (visual-line-mode) + (whitespace-mode) + (setq tab-width 8) + (flycheck-mode) + )) + +(defun rust-run-current-buffers-file () + "run a command on the current file" + (interactive) + (shell-command + (format "rust run %s 2>&1 | grep -v 'no debug symbols in executable'" + (shell-quote-argument (buffer-file-name)))) +) + +(defun rust-test-current-buffers-file () + "run a command on the current file" + (interactive) + (shell-command + (format "rust test %s 2>&1 | grep -v 'no debug symbols in executable'" + (shell-quote-argument (buffer-file-name)))) +) + +(eval-after-load 'rust-mode + '(define-key rust-mode-map (kbd "C-c C-r") 'rust-run-current-buffers-file)) +(eval-after-load 'rust-mode + '(define-key rust-mode-map (kbd "C-S-t") 'rust-test-current-buffers-file)) diff --git a/emacs/.emacs.d/modes/shell.el b/emacs/.emacs.d/modes/shell.el new file mode 100644 index 0000000..57f2715 --- /dev/null +++ b/emacs/.emacs.d/modes/shell.el @@ -0,0 +1,18 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(autoload 'sh--mode "sh-mode" "mode for shell stuff" t) + +(add-to-list 'auto-mode-alist '("\\.sh$\\'" . sh-mode)) +(add-to-list 'auto-mode-alist '("\\.[zk]sh$\\'" . sh-mode)) +(add-to-list 'auto-mode-alist '("\\.bash$\\'" . sh-mode)) +(add-to-list 'auto-mode-alist '("\\[.].*shrc$\\'" . sh-mode)) +(add-to-list 'auto-mode-alist '("sourceme$\\'" . sh-mode)) + +(add-hook 'sh-mode-hook + '(lambda () + (load "mode-defaults") + (smartparens-mode) + (flycheck-mode) + (setq-default indent-tabs-mode nil) + (setq sh-basic-offset 2 sh-indentation 4 + sh-indent-for-case-label 0 sh-indent-for-case-alt '+))) diff --git a/emacs/.emacs.d/package-settings/autopair.el b/emacs/.emacs.d/package-settings/autopair.el new file mode 100644 index 0000000..f356753 --- /dev/null +++ b/emacs/.emacs.d/package-settings/autopair.el @@ -0,0 +1,5 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; autopair, its awesome for non lisps and ()'s []'s etc... +(require 'autopair nil 'noerror) +(setq autopair-blink 'nil) diff --git a/emacs/.emacs.d/package-settings/color-theme.el b/emacs/.emacs.d/package-settings/color-theme.el new file mode 100644 index 0000000..dd9d524 --- /dev/null +++ b/emacs/.emacs.d/package-settings/color-theme.el @@ -0,0 +1,21 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; use gtk-ide for my color theme, solarized has... issues. +;; aka with it setup, even from latest git source, it seems to crash +;; connections with emacsclient due to some face issue. +;; so eff it, ignore the thing. TODO: find out how/why +;; emacs segv's on linux/osx with it on, but i'm lazy prolly won't +(color-theme-initialize) + +(if (or window-system osx-p) + (color-theme-gtk-ide) + (color-theme-hober)) + +(unless (or window-system osx-p) + (color-theme-install-frame-params + '((background-color . "white")))) + +;; fixup multi-term fg/bg color support as it doesn't always +;; pickup defaults +(setq term-default-bg-color (face-background 'default)) +(setq term-default-fg-color (face-foreground 'default)) diff --git a/emacs/.emacs.d/package-settings/expand-region.el b/emacs/.emacs.d/package-settings/expand-region.el new file mode 100644 index 0000000..3c150fd --- /dev/null +++ b/emacs/.emacs.d/package-settings/expand-region.el @@ -0,0 +1,4 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; expand region is awesome for selecting ever increasing regions. +(global-set-key (kbd "C-]") 'er/expand-region) diff --git a/emacs/.emacs.d/package-settings/flycheck.el b/emacs/.emacs.d/package-settings/flycheck.el new file mode 100644 index 0000000..426fe80 --- /dev/null +++ b/emacs/.emacs.d/package-settings/flycheck.el @@ -0,0 +1,26 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; flymake is old, lets use something better. +(setq flycheck-indication-mode 'right-fringe) + +;; Test out grizzl for completions. +;;(setq flycheck-select-checker 'grizzl) + +;; Make flycheck able to parse CFLAGS from pkg-config +(defun pkg-config-add-lib-cflags (pkg-config-lib) + "This function will add necessary header file path of a +specified by `pkg-config-lib' to `flycheck-clang-include-path', which make it +completionable by auto-complete-clang" + (interactive "spkg-config lib: ") + (if (executable-find "pkg-config") + (if (= (shell-command + (format "pkg-config %s" pkg-config-lib)) + 0) + (setq flycheck-clang-include-path + (append flycheck-clang-include-path + (split-string + (shell-command-to-string + (format "pkg-config --cflags-only-I %s" + pkg-config-lib))))) + (message "Error, pkg-config lib %s not found." pkg-config-lib)) + (message "Error: pkg-config tool not found."))) diff --git a/emacs/.emacs.d/package-settings/magit-mode.el b/emacs/.emacs.d/package-settings/magit-mode.el new file mode 100644 index 0000000..85c9aa5 --- /dev/null +++ b/emacs/.emacs.d/package-settings/magit-mode.el @@ -0,0 +1,4 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; make magit mode simpler to use +(global-set-key (kbd "C-x m") 'magit-status) diff --git a/emacs/.emacs.d/package-settings/misc.el b/emacs/.emacs.d/package-settings/misc.el new file mode 100644 index 0000000..5998e11 --- /dev/null +++ b/emacs/.emacs.d/package-settings/misc.el @@ -0,0 +1,2 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(move-text-default-bindings) diff --git a/emacs/.emacs.d/package-settings/multi-term.el b/emacs/.emacs.d/package-settings/multi-term.el new file mode 100644 index 0000000..8e9a214 --- /dev/null +++ b/emacs/.emacs.d/package-settings/multi-term.el @@ -0,0 +1,26 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; multi-term only on non-windows, stupid windows command line +(unless mswindows-p + ;; multi-term setup + (autoload 'multi-term "multi-term" nil t) + (autoload 'multi-term-next "multi-term" nil t) + + ;; fuck you audible beeps + (setq ring-bell-function (lambda () (message "*beep beep imma jeep*"))) + + ;; try and use zsh when we can, cause bourne/bourne-again are the suck + (setq multi-term-program (cond + ((file-exists-p "/bin/zsh") "/bin/zsh") + ((file-exists-p "/usr/bin/zsh") "/usr/bin/zsh") + ((t) "/bin/sh");; fine use whatever the hell /bin/sh is + )) + + ;; allow switching to the next terminal in line + (global-set-key (kbd "C-c C-t") 'multi-term-next) + + ;; zomg annoying, term-unbind-key-list is what it unbinds, not what you want + ;; to unbind. bit of a logic weirdout in my mind. + ;; aka, what is in the term-unbind-key-list is what you can type to the terminal + (setq term-unbind-key-list '("C-x" "C-y" "M-x")) + ) diff --git a/emacs/.emacs.d/package-settings/org.el b/emacs/.emacs.d/package-settings/org.el new file mode 100644 index 0000000..f0dfb80 --- /dev/null +++ b/emacs/.emacs.d/package-settings/org.el @@ -0,0 +1,12 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(require 'org-install) +(add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) + +(define-key global-map "\C-ca" 'org-agenda) +(define-key global-map "\C-cb" 'org-iswitchb) +(define-key global-map "\C-cc" 'org-capture) +(define-key global-map "\C-cl" 'org-store-link) +(define-key global-map "\C-cp" 'org-latex-export-to-pdf) + +(setq org-log-done t) diff --git a/emacs/.emacs.d/package-settings/uniquify.el b/emacs/.emacs.d/package-settings/uniquify.el new file mode 100644 index 0000000..3870472 --- /dev/null +++ b/emacs/.emacs.d/package-settings/uniquify.el @@ -0,0 +1,5 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; setup uniquify for buffer names +(require 'uniquify) +(setq uniquify-buffer-name-style 'post-forward) diff --git a/emacs/.emacs.d/settings/clang-format.el b/emacs/.emacs.d/settings/clang-format.el new file mode 100644 index 0000000..c2878ad --- /dev/null +++ b/emacs/.emacs.d/settings/clang-format.el @@ -0,0 +1,11 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(when osx-p + (setq exec-path + (append exec-path + '("/Users/mitch/homebrew/Cellar/llvm/3.4/bin")))) +(when linux-p + (setq exec-path (append '("/home/mitch/local/bin") exec-path))) + +(load "~/.emacs.d/misc/clang-format.el") +(global-set-key [C-M-tab] 'clang-format-region) diff --git a/emacs/.emacs.d/settings/defaults.el b/emacs/.emacs.d/settings/defaults.el new file mode 100644 index 0000000..ecdbe72 --- /dev/null +++ b/emacs/.emacs.d/settings/defaults.el @@ -0,0 +1,9 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; Get rid of all of the stupid "look here's emacs" kthxbai +(setq inhibit-startup-message t) +(setq inhibit-startup-screen t) +(setq inhibit-startup-echo-area-message t) + +;; Update non-edited files changed on disk automatically +(setq global-auto-revert-mode t) diff --git a/emacs/.emacs.d/settings/desktop.el b/emacs/.emacs.d/settings/desktop.el new file mode 100644 index 0000000..7bd7180 --- /dev/null +++ b/emacs/.emacs.d/settings/desktop.el @@ -0,0 +1,18 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; desktop saving for session sanity, add a hook into auto-save-hook +;; to save it at logical times +(require 'desktop) + +(desktop-save-mode 1) + +(setq desktop-path '("~/.emacs.d/")) +(setq desktop-dirname "~/.emacs.d") +(setq desktop-base-file-name ".emacs.desktop") + +(defun local-desktop-save () + (interactive) + (if (eq (desktop-owner) (emacs-pid)) + (desktop-save desktop-dirname))) + +(add-hook 'auto-save-hook 'desktop-save-in-desktop-dir) diff --git a/emacs/.emacs.d/settings/dired-x.el b/emacs/.emacs.d/settings/dired-x.el new file mode 100644 index 0000000..483e634 --- /dev/null +++ b/emacs/.emacs.d/settings/dired-x.el @@ -0,0 +1,2 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(add-hook 'dired-load-hook (function (lambda () (load "dired-x")))) diff --git a/emacs/.emacs.d/settings/display.el b/emacs/.emacs.d/settings/display.el new file mode 100644 index 0000000..756cffe --- /dev/null +++ b/emacs/.emacs.d/settings/display.el @@ -0,0 +1,25 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; if I selected it, deleting it is OK kthxbai +(delete-selection-mode 1) + +;; be more like vi, display line/col always +(custom-set-variables '(line-number-mode t)) +(custom-set-variables '(column-number-mode t)) + +;; 80 char lines not 72 +(custom-set-variables '(fill-column 80)) + +;; ok, double spacing after a period for sentences +;; is fucking archaic, we don't use typewriters any longer +(set-default 'sentence-end-double-space nil) + +;; What emacs thinks a sentence ending is, make it less derp. +(custom-set-variables '(sentence-end "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*")) +(custom-set-variables '(sentence-end-double-space nil)) + +;; Tabs suck, no +(custom-set-variables '(default-tab-width 2)) + +;; Always remove trailing whitespace +(add-hook 'before-save-hook 'delete-trailing-whitespace) diff --git a/emacs/.emacs.d/settings/ediff.el b/emacs/.emacs.d/settings/ediff.el new file mode 100644 index 0000000..abb3cd3 --- /dev/null +++ b/emacs/.emacs.d/settings/ediff.el @@ -0,0 +1,4 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(setq ediff-window-setup-function 'ediff-setup-windows-plain) +(setq ediff-split-window-function 'split-window-horizontally) diff --git a/emacs/.emacs.d/settings/encoding.el b/emacs/.emacs.d/settings/encoding.el new file mode 100644 index 0000000..528d9af --- /dev/null +++ b/emacs/.emacs.d/settings/encoding.el @@ -0,0 +1,8 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; utf8 by default +(custom-set-variables '(locale-coding-system 'utf-8)) +(set-terminal-coding-system 'utf-8) +(set-keyboard-coding-system 'utf-8) +(set-selection-coding-system 'utf-8) +(prefer-coding-system 'utf-8) diff --git a/emacs/.emacs.d/settings/file-templates.el b/emacs/.emacs.d/settings/file-templates.el new file mode 100644 index 0000000..5f98dd6 --- /dev/null +++ b/emacs/.emacs.d/settings/file-templates.el @@ -0,0 +1,45 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; Default file template definitions +(add-hook 'find-file-hooks 'maybe-load-template) + +(setq template-file-prefix (concat (getenv "HOME") "/.emacs.d/templates")) + +(defun maybe-load-template () + (interactive) + (when (and + (string-match "\\.rb$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/ruby.rb")) + (ruby-mode)) + (when (and + (string-match "\\.sh$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/shell.sh")) + (sh-mode)) + (when (and + (string-match "\\.ksh$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/shell.ksh")) + (sh-mode)) + (when (and + (string-match "\\.pl$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/perl.pl")) + (perl-mode)) + (when (and + (string-match "\\.py$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/python.py")) + (python-mode)) + (when (and + (string-match "\\.pm$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/perl-module.pm")) + (perl-mode)) + (when (and + (string-match "\\.el$" (buffer-file-name)) + (eq 1 (point-max))) + (insert-file (concat template-file-prefix "/elisp.el")) + (emacs-lisp-mode)) +) diff --git a/emacs/.emacs.d/settings/font.el b/emacs/.emacs.d/settings/font.el new file mode 100644 index 0000000..ce3f4ac --- /dev/null +++ b/emacs/.emacs.d/settings/font.el @@ -0,0 +1,21 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(when window-system + (require 'cl) + + (defun font-candidate (&rest fonts) + "Return first font that matches list of provided fonts." + (find-if (lambda (f) (find-font (font-spec :name f))) fonts)) + + ;; Try out these fonts in order of preference depending on install status. + (set-face-attribute 'default nil :font + (font-candidate '"Source Code Pro-14:weight=normal" + "Menlo-12:weight=normal" + "Monaco-12:weight=normal")) + + (cond (linux-p + (setq interprogram-paste-function 'x-cut-buffer-or-selection-value) + (setq x-select-enable-clipboard t) + ) + ) + ) diff --git a/emacs/.emacs.d/settings/keybindings.el b/emacs/.emacs.d/settings/keybindings.el new file mode 100644 index 0000000..d1fadc5 --- /dev/null +++ b/emacs/.emacs.d/settings/keybindings.el @@ -0,0 +1,16 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; show what is being typed quicker +(custom-set-variables '(echo-keystrokes 0.1)) + +;; Let shift+arrow keys change panes +(require 'windmove) +(windmove-default-keybindings) + +;; Ok, so make it possible to use option+char on osx to type accented +;; chars in cocoa emacs. +;; Also makes command is meta. +(when window-system + (cond (osx-p + (setq mac-option-modifier 'none) + (setq mac-command-modifier 'meta)))) diff --git a/emacs/.emacs.d/settings/minimalism.el b/emacs/.emacs.d/settings/minimalism.el new file mode 100644 index 0000000..8108ab3 --- /dev/null +++ b/emacs/.emacs.d/settings/minimalism.el @@ -0,0 +1,9 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(when window-system + (tool-bar-mode -1)) + +(when window-system + (scroll-bar-mode -1)) + +(menu-bar-mode -1) diff --git a/emacs/.emacs.d/settings/misc.el b/emacs/.emacs.d/settings/misc.el new file mode 100644 index 0000000..85acaa4 --- /dev/null +++ b/emacs/.emacs.d/settings/misc.el @@ -0,0 +1,33 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; use incremental complete mode for the minibuffer +(icomplete-mode) + +;; highlight parens n stuff +(show-paren-mode) + +;; y/n is good enough +(defalias 'yes-or-no-p 'y-or-n-p) + +;; Default major mode is just text +(custom-set-variables '(default-major-mode 'text-mode)) + +;; Don't clobber minibuffer text +(custom-set-variables '(help-at-pt-timer-delay 0.9)) + +;; Auto chmod u+x on scripts, because why wouldn't you? +(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) + +;; Ok backup files are annoying +(setq make-backup-files nil) +(setq auto-save-default nil) + +;; What to do with backup crap/autosave files +(setq backup-by-copying t) +(setq backup-directory-alist + `((".*" . ,user-temporary-file-directory) + (,tramp-file-name-regexp nil))) +(setq auto-save-list-file-prefix + (concat user-temporary-file-directory ".auto-saves-")) +(setq auto-save-file-name-transforms + `((".*" ,user-temporary-file-directory t))) diff --git a/emacs/.emacs.d/settings/modeline.el b/emacs/.emacs.d/settings/modeline.el new file mode 100644 index 0000000..d36cc49 --- /dev/null +++ b/emacs/.emacs.d/settings/modeline.el @@ -0,0 +1,33 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(custom-set-variables '(mode-line-format + (list + '(:eval (propertize "%b " 'face 'font-lock-keyword-face + 'help-echo (buffer-file-name))) + (propertize "%02l" 'face 'font-lock-type-face) "," + (propertize "%02c" 'face 'font-lock-type-face) + " [" + '(:eval (propertize "%m" 'face 'font-lock-string-face + 'help-echo buffer-file-coding-system)) + minor-mode-alist + "] " + "[" + '(:eval (propertize (if overwrite-mode "Ovr" "Ins") + 'face 'font-lock-preprocessor-face + 'help-echo (concat "Buffer is in " + (if overwrite-mode "overwrite" "insert") " mode"))) + '(:eval (when (buffer-modified-p) + (concat "," (propertize "Mod" + 'face 'font-lock-warning-face + 'help-echo "Buffer has been modified")))) + '(:eval (when buffer-read-only + (concat "," (propertize "RO" + 'face 'font-lock-type-face + 'help-echo "Buffer is read-only")))) "] " + '(:eval (propertize (format-time-string "%H:%M:%S") + 'help-echo + (concat (format-time-string "%c; ") + (emacs-uptime "Uptime:%hh")))) + " --" + "%-" + ))) diff --git a/emacs/.emacs.d/settings/modes.el b/emacs/.emacs.d/settings/modes.el new file mode 100644 index 0000000..d397087 --- /dev/null +++ b/emacs/.emacs.d/settings/modes.el @@ -0,0 +1,4 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; Load/setup mode hook file(s) in ~/modes +(mapcar 'load-file (directory-files "~/.emacs.d/modes" t ".*.el$")) diff --git a/emacs/.emacs.d/settings/mouse.el b/emacs/.emacs.d/settings/mouse.el new file mode 100644 index 0000000..1a01869 --- /dev/null +++ b/emacs/.emacs.d/settings/mouse.el @@ -0,0 +1,9 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +(unless window-system + (require 'mouse) + (xterm-mouse-mode t) + (defun track-mouse (e)) + (setq mouse-sel-mode t) + (global-set-key [mouse-5] '(lambda () (interactive) (scroll-up 1))) + (global-set-key [mouse-4] '(lambda () (interactive) (scroll-down 1)))) diff --git a/emacs/.emacs.d/settings/recentf.el b/emacs/.emacs.d/settings/recentf.el new file mode 100644 index 0000000..863b110 --- /dev/null +++ b/emacs/.emacs.d/settings/recentf.el @@ -0,0 +1,5 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- +(require 'recentf) +(recentf-mode 1) +(setq recentf-max-menu-items 25) +(global-set-key "\C-x\ \C-r" 'recentf-open-files) diff --git a/emacs/.emacs.d/settings/time.el b/emacs/.emacs.d/settings/time.el new file mode 100644 index 0000000..ef2329b --- /dev/null +++ b/emacs/.emacs.d/settings/time.el @@ -0,0 +1,11 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; I only want the time in my modeline, not system load +;; %T is HH:MM:SS basically +;; Also update every 5 seconds instead of 60 +(custom-set-variables '(display-time-default-load-average nil)) +(custom-set-variables '(display-time-format "%T")) +(custom-set-variables '(display-time-interval 5)) + +;; Set the time in the mode line +(display-time-mode) diff --git a/emacs/.emacs.d/settings/tramp.el b/emacs/.emacs.d/settings/tramp.el new file mode 100644 index 0000000..08fade2 --- /dev/null +++ b/emacs/.emacs.d/settings/tramp.el @@ -0,0 +1,27 @@ +;-*-mode: emacs-lisp; coding: utf-8;-*- + +; Tramp mode setup +(require 'tramp) + +; Make the default proxy list sane(r) +(set-default 'tramp-default-proxies-alist + (quote ((".*" "\\`root\\'" "/ssh:%h:")))) + +; Since work sudo only allows for su with sudo. +; We add a new 'susudo' method that uses +; sudo args USER su -c 'command you wanted to run' +; instead of sudo command +; gay but pci "security" can be pretty dumb +(add-to-list 'tramp-methods + '("susudo" + (tramp-login-program "sudo") + (tramp-login-args + (("-u" "%u") + ("-H") + ("-p" "Password:") + ("su -c /bin/sh"))) + (tramp-remote-sh "/bin/sh") + (tramp-copy-program nil) + (tramp-copy-args nil) + (tramp-copy-keep-date nil) + (tramp-password-end-of-line nil))) diff --git a/emacs/.emacs.d/settings/whitespace.el b/emacs/.emacs.d/settings/whitespace.el new file mode 100644 index 0000000..a596ede --- /dev/null +++ b/emacs/.emacs.d/settings/whitespace.el @@ -0,0 +1,14 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- + +;; Setup whitespace mode to highlight tabs and over 80 char spaces +(require 'whitespace) + +(setq whitespace-style '(face tabs trailing)) + +(set-face-attribute 'whitespace-tab nil + :foreground "#2075c7" + :background "lightgrey") + +(set-face-attribute 'whitespace-line nil + :foreground "#2075c7" + :background "lightgrey") diff --git a/emacs/.emacs.d/templates/elisp.el b/emacs/.emacs.d/templates/elisp.el new file mode 100644 index 0000000..89c96ed --- /dev/null +++ b/emacs/.emacs.d/templates/elisp.el @@ -0,0 +1 @@ +;;-*-mode: emacs-lisp; coding: utf-8;-*- diff --git a/emacs/.emacs.d/templates/perl-module.pm b/emacs/.emacs.d/templates/perl-module.pm new file mode 100644 index 0000000..ff811a6 --- /dev/null +++ b/emacs/.emacs.d/templates/perl-module.pm @@ -0,0 +1,18 @@ +#-*-mode: Perl; coding: utf-8;-*- +package MyModule; + +use strict; +use Exporter; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +$VERSION = 1.00; +@ISA = qw(Exporter); +@EXPORT = (); +@EXPORT_OK = qw(func1 func2); +%EXPORT_TAGS = ( DEFAULT => [qw(&func1)], + Both => [qw(&func1 &func2)]); + +sub func1 { return reverse @_ } +sub func2 { return map{ uc }@_ } + +1; diff --git a/emacs/.emacs.d/templates/perl.pl b/emacs/.emacs.d/templates/perl.pl new file mode 100644 index 0000000..f6f5206 --- /dev/null +++ b/emacs/.emacs.d/templates/perl.pl @@ -0,0 +1,3 @@ +#!/usr/bin/env perl +#-*-mode: Perl; coding: utf-8;-*- + diff --git a/emacs/.emacs.d/templates/python.py b/emacs/.emacs.d/templates/python.py new file mode 100644 index 0000000..6c3ee44 --- /dev/null +++ b/emacs/.emacs.d/templates/python.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python +# -*-mode: Python; coding: utf-8;-*- + diff --git a/emacs/.emacs.d/templates/ruby.rb b/emacs/.emacs.d/templates/ruby.rb new file mode 100644 index 0000000..42a8d45 --- /dev/null +++ b/emacs/.emacs.d/templates/ruby.rb @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +#-*-mode: Ruby; coding: utf-8;-*- + diff --git a/emacs/.emacs.d/templates/shell.ksh b/emacs/.emacs.d/templates/shell.ksh new file mode 100755 index 0000000..266e17a --- /dev/null +++ b/emacs/.emacs.d/templates/shell.ksh @@ -0,0 +1,5 @@ +#!/usr/bin/env ksh +#-*-mode: Shell-script; coding: utf-8;-*- +script=$(basename $0) +dir=$(cd $(dirname $0); pwd) +iam=${dir}/${script} diff --git a/emacs/.emacs.d/templates/shell.sh b/emacs/.emacs.d/templates/shell.sh new file mode 100755 index 0000000..3727559 --- /dev/null +++ b/emacs/.emacs.d/templates/shell.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +#-*-mode: Shell-script; coding: utf-8;-*- +script=$(basename $0) +dir=$(cd $(dirname $0); pwd) +iam=${dir}/${script} diff --git a/emacs/.emacs.d/yasnippet/c-mode/assert b/emacs/.emacs.d/yasnippet/c-mode/assert new file mode 100644 index 0000000..ec072a6 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/assert @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: assert(...); +# key: assert/ +# -- +assert(${1:0 == 1}); diff --git a/emacs/.emacs.d/yasnippet/c-mode/compoundliteral b/emacs/.emacs.d/yasnippet/c-mode/compoundliteral new file mode 100644 index 0000000..1e0c76e --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/compoundliteral @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: {...} *... = ({...}[]){...}; +# key: literal/ +# -- +${1:double} *${2:name} = ($1[]){${3:1.1, NAN}}; diff --git a/emacs/.emacs.d/yasnippet/c-mode/doxygen b/emacs/.emacs.d/yasnippet/c-mode/doxygen new file mode 100644 index 0000000..336dba8 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/doxygen @@ -0,0 +1,10 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: doxygen comment +# key: dox/ +# -- +/** + \brief ${1:brief comment} + ${0:long explanation of boring} + \param ${3:param1}, ${4:value} + \returns ${5:returns whatever} +*/ diff --git a/emacs/.emacs.d/yasnippet/c-mode/enum b/emacs/.emacs.d/yasnippet/c-mode/enum new file mode 100644 index 0000000..a0efe9b --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/enum @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: typedef enum { ... } ...; +# key: enum/ +# -- +typedef enum { + ${0:values_and_such} +} ${1:name}_t; diff --git a/emacs/.emacs.d/yasnippet/c-mode/for b/emacs/.emacs.d/yasnippet/c-mode/for new file mode 100644 index 0000000..7858f83 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/for @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: for (...; ...; ...) { ... } +# key: for/ +# -- +for (${1:int i = 0}; ${2:i < N}; ${3:i++}){ + ${0:0 == 0;} +} diff --git a/emacs/.emacs.d/yasnippet/c-mode/for.1 b/emacs/.emacs.d/yasnippet/c-mode/for.1 new file mode 100644 index 0000000..3a20e1f --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/for.1 @@ -0,0 +1,6 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: for (...; ...; ...) ... +# key: for/ +# -- +for (${1:int i = 0}; ${2:i < N}; ${3:i++}) + ${0:0 == 0;} diff --git a/emacs/.emacs.d/yasnippet/c-mode/free b/emacs/.emacs.d/yasnippet/c-mode/free new file mode 100644 index 0000000..365b7ab --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/free @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: free(...); +# key: free/ +# -- +free(${1:stuff}); diff --git a/emacs/.emacs.d/yasnippet/c-mode/function b/emacs/.emacs.d/yasnippet/c-mode/function new file mode 100644 index 0000000..02b92a3 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/function @@ -0,0 +1,8 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: insert a function +# key: fn/ +# -- +${1:void} ${2:function_name}(${3:args}) { + $0 + return ${4:NULL}; +} diff --git a/emacs/.emacs.d/yasnippet/c-mode/functionprototype b/emacs/.emacs.d/yasnippet/c-mode/functionprototype new file mode 100644 index 0000000..5baf41d --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/functionprototype @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: insert a function prototype +# key: fnp/ +# -- +${1:void} ${2:function_name}(${3:args}); diff --git a/emacs/.emacs.d/yasnippet/c-mode/functionwithprototype b/emacs/.emacs.d/yasnippet/c-mode/functionwithprototype new file mode 100644 index 0000000..0084d82 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/functionwithprototype @@ -0,0 +1,9 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: insert a function with prototype +# key: func/ +# -- +${1:void} ${2:function_name}(${3:args}); +$1 $2($3){ + $0 + return ${4:NULL}; +} diff --git a/emacs/.emacs.d/yasnippet/c-mode/guard b/emacs/.emacs.d/yasnippet/c-mode/guard new file mode 100644 index 0000000..5316076 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/guard @@ -0,0 +1,8 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: #ifndef XXX; #define XXX; #endif +# key: guard/ +# -- +#ifndef ${1:_`(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`_H_} +#define $1 +${0:some_header_guarded_stuff} +#endif /* $1 */ \ No newline at end of file diff --git a/emacs/.emacs.d/yasnippet/c-mode/ifdef b/emacs/.emacs.d/yasnippet/c-mode/ifdef new file mode 100644 index 0000000..74e8b0e --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/ifdef @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: #ifdef ...; ...; #endif +# key: ifdef/ +# -- +#ifdef ${1:somedef} +${0:somedef_guarded_junk} +#endif diff --git a/emacs/.emacs.d/yasnippet/c-mode/include b/emacs/.emacs.d/yasnippet/c-mode/include new file mode 100644 index 0000000..d201959 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/include @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: #include "...\.h" +# key: inc/ +# -- +#include "${1:someuserheader}.h" diff --git a/emacs/.emacs.d/yasnippet/c-mode/include.1 b/emacs/.emacs.d/yasnippet/c-mode/include.1 new file mode 100644 index 0000000..1edf651 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/include.1 @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: #include <...\.h> +# key: inc/ +# -- +#include <${1:somesystemheader}.h> diff --git a/emacs/.emacs.d/yasnippet/c-mode/main b/emacs/.emacs.d/yasnippet/c-mode/main new file mode 100644 index 0000000..38cb278 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/main @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: int main(argc, argv) { ... } +# key: main/ +# -- +int main(int argc, char *argv[]) { + $0 +} diff --git a/emacs/.emacs.d/yasnippet/c-mode/main.1 b/emacs/.emacs.d/yasnippet/c-mode/main.1 new file mode 100644 index 0000000..cafdb06 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/main.1 @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: int main(void) { ... } +# key: main/ +# -- +int main(void) { + $0 +} diff --git a/emacs/.emacs.d/yasnippet/c-mode/malloc b/emacs/.emacs.d/yasnippet/c-mode/malloc new file mode 100644 index 0000000..b65530e --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/malloc @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: malloc(...); +# key: malloc/ +# -- +malloc(${1:stuff}); diff --git a/emacs/.emacs.d/yasnippet/c-mode/pragma-clang-ignore b/emacs/.emacs.d/yasnippet/c-mode/pragma-clang-ignore new file mode 100644 index 0000000..a30df65 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/pragma-clang-ignore @@ -0,0 +1,12 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: insert clang pragma to ignore some warning +# key: cprag/ +# -- +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-W${1:somewarning}" +#endif +${0:some_evil_codez} +#ifdef __clang__ +#pragma clang diagnostic pop +#endif \ No newline at end of file diff --git a/emacs/.emacs.d/yasnippet/c-mode/pragma-gcc-ignore b/emacs/.emacs.d/yasnippet/c-mode/pragma-gcc-ignore new file mode 100644 index 0000000..3518d88 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/pragma-gcc-ignore @@ -0,0 +1,12 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: insert gcc pragma to ignore some warning +# key: gprag/ +# -- +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-W${1:somewarning}" +#endif +${0:some_evil_codez} +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif \ No newline at end of file diff --git a/emacs/.emacs.d/yasnippet/c-mode/printf b/emacs/.emacs.d/yasnippet/c-mode/printf new file mode 100644 index 0000000..7e221bd --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/printf @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: printf +# contributor: joaotavora +# key: printf/ +# -- +printf("${1:%s}\\n"${1:$(if (string-match "%" yas-text) "," "\);") +}$2${1:$(if (string-match "%" yas-text) "\);" "")} diff --git a/emacs/.emacs.d/yasnippet/c-mode/puts b/emacs/.emacs.d/yasnippet/c-mode/puts new file mode 100644 index 0000000..171ffbb --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/puts @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: puts(...); +# key: puts/ +# -- +puts(${1:stuff}); diff --git a/emacs/.emacs.d/yasnippet/c-mode/static_const b/emacs/.emacs.d/yasnippet/c-mode/static_const new file mode 100644 index 0000000..3cc001e --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/static_const @@ -0,0 +1,5 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: static const ... ... = ...; +# key: sconst/ +# -- +static const ${1:int} ${2:FOO} = 1; diff --git a/emacs/.emacs.d/yasnippet/c-mode/struct b/emacs/.emacs.d/yasnippet/c-mode/struct new file mode 100644 index 0000000..fedf781 --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/struct @@ -0,0 +1,7 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: struct ... { ... } +# key: struct/ +# -- +typedef struct { + ${0:some_struct_stuffs} +} ${1:name}_s; \ No newline at end of file diff --git a/emacs/.emacs.d/yasnippet/c-mode/switch b/emacs/.emacs.d/yasnippet/c-mode/switch new file mode 100644 index 0000000..6269cdc --- /dev/null +++ b/emacs/.emacs.d/yasnippet/c-mode/switch @@ -0,0 +1,11 @@ +#-*- mode: snippet; coding: utf-8 -*- +# name: switch(...) {case ... : ... break; default : ...} +# key: switch/ +# -- +switch (${1:something}){ + case ${2:constant_expression} : + ${0:fill_me_in_dork} + break; + default : + ${3:default_thing_to_do} +} diff --git a/emacs/.profile.d/99-alias-emacs.sh b/emacs/.profile.d/99-alias-emacs.sh new file mode 100644 index 0000000..2e7c4d9 --- /dev/null +++ b/emacs/.profile.d/99-alias-emacs.sh @@ -0,0 +1,8 @@ +# emacs/.profile.d/99-alias-emacs.sh +alias e=emacs +alias de=emacs --debug-init -nw +alias ec=emacsclient +alias ect=emacsclient -t +alias oec=emacsclient -n -c +alias stope=emacsclient -t -e "(save-buffers-kill-emacs)(kill-emacs)" +alias kille=emacsclient -e "(kill-emacs)" diff --git a/git/.gitconfig.d/00-user b/git/.gitconfig.d/00-user new file mode 100644 index 0000000..6c8d8b3 --- /dev/null +++ b/git/.gitconfig.d/00-user @@ -0,0 +1,3 @@ +[user] + email = mitch.tishmack@gmail.com + name = Mitch Tishmack diff --git a/git/.gitconfig.d/10-core b/git/.gitconfig.d/10-core new file mode 100644 index 0000000..bb4a160 --- /dev/null +++ b/git/.gitconfig.d/10-core @@ -0,0 +1,20 @@ +[alias] + up = !sh -c 'git pull --rebase && git push' + # 1.8.4+ only for ignore-all-space + wsldiff = diff --color-words --ignore-space-at-eol --ignore-space-change --ignore-all-space --ignore-all-space + wsdiff = diff --color-words --ignore-space-at-eol --ignore-space-change --ignore-all-space + wdiff = diff --color-words + ci = commit + ciu = commit --all + co = checkout + ba = branch --all + st = status --short --branch + pak = repack -a -d -f --depth=2000 --window=2000 + unstage = reset HEAD + tlog = log --graph --color=always --abbrev-commit --date=relative --pretty=oneline + hist = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative + slog = log --oneline --decorate + fixup = commit --fixup + squash = commit --squash + ri = rebase --interactive --autosquash + ra = rebase --abort diff --git a/git/.gitconfig.d/20-color-setup b/git/.gitconfig.d/20-color-setup new file mode 100644 index 0000000..07db50b --- /dev/null +++ b/git/.gitconfig.d/20-color-setup @@ -0,0 +1,19 @@ +[pager] + color = true +[color] + status = auto + diff = auto + branch = auto +[color "status"] + added = green + changed = blue + untracked = red +[color "branch"] + current = green + local = blue + remote = red +[color "diff"] + meta = blue bold + frag = black reverse + old = red reverse + new = green reverse diff --git a/git/.gitconfig.d/30-gui-stuff b/git/.gitconfig.d/30-gui-stuff new file mode 100644 index 0000000..2867c06 --- /dev/null +++ b/git/.gitconfig.d/30-gui-stuff @@ -0,0 +1,5 @@ +[advice] + statushints = false +[gui] + fontui = -family Monaco -size 8 -weight normal -slant roman -underline 0 -overstrike 0 + fontdiff = -family Monaco -size 8 -weight normal -slant roman -underline 0 -overstrike 0 diff --git a/git/.gitconfig.d/40-github b/git/.gitconfig.d/40-github new file mode 100644 index 0000000..427cffa --- /dev/null +++ b/git/.gitconfig.d/40-github @@ -0,0 +1,2 @@ +[github] + user = mitchty diff --git a/git/.gitconfig.d/5-http b/git/.gitconfig.d/5-http new file mode 100644 index 0000000..4a4f009 --- /dev/null +++ b/git/.gitconfig.d/5-http @@ -0,0 +1,4 @@ +[http] + postBuffer = 209715200 +[push] + default = simple diff --git a/git/.gitconfig.d/50-gpg b/git/.gitconfig.d/50-gpg new file mode 100644 index 0000000..98c654c --- /dev/null +++ b/git/.gitconfig.d/50-gpg @@ -0,0 +1,2 @@ +[credential] + helper = netrc -v -f ~/.netrc.gpg -f ~/.netrc diff --git a/git/.gitignore b/git/.gitignore new file mode 100644 index 0000000..5ba8a88 --- /dev/null +++ b/git/.gitignore @@ -0,0 +1,12 @@ +.*~ +*~ +.\#* +\#* +\#*\# +.\#*\# +.DS_Store +*.pyc +*.rbc +*.elc +*.swp +*.[oa] diff --git a/git/.profile.d/99-alias-git.sh b/git/.profile.d/99-alias-git.sh new file mode 100644 index 0000000..bc04c55 --- /dev/null +++ b/git/.profile.d/99-alias-git.sh @@ -0,0 +1,2 @@ +# git/.profile.d/99-alias-git.sh +alias g=git diff --git a/haskell/.ghci b/haskell/.ghci new file mode 100644 index 0000000..31f559e --- /dev/null +++ b/haskell/.ghci @@ -0,0 +1 @@ +:set prompt "λ " diff --git a/osx/.profile.d/01-ps1-osx.sh b/osx/.profile.d/01-ps1-osx.sh new file mode 100644 index 0000000..29224e2 --- /dev/null +++ b/osx/.profile.d/01-ps1-osx.sh @@ -0,0 +1,3 @@ +# osx/.profile.d/01-ps1-osx.sh +_host=$(hostname -s) +export _host diff --git a/osx/.profile.d/99-alias.sh b/osx/.profile.d/99-alias.sh new file mode 100644 index 0000000..c83ee9f --- /dev/null +++ b/osx/.profile.d/99-alias.sh @@ -0,0 +1,2 @@ +# osx/.profile.d/99-alias.sh +alias o='open -a' diff --git a/perl/.perlcriticrc b/perl/.perlcriticrc new file mode 100644 index 0000000..f986d16 --- /dev/null +++ b/perl/.perlcriticrc @@ -0,0 +1,49 @@ +# Show the severity level +severity = 1 + +# Basically show what profile is complaining +verbose = %f:%l:%c: %m, %e (%p, severity %s)\n + +# Don't warn on these variables +[Variables::ProhibitPunctuationVars] +allow = $@ $! + +# Ignore syscall returns on print, it not actually returning is... whatever. +[InputOutput::RequireCheckedSyscalls] +exclude_functions = print say + +# Allow things like print qx(somecmd) in a void context to work, this is ok. +[InputOutput::ProhibitBacktickOperators] +only_in_void_context = 1 + +# I actually like using unless... so don't piss me off whinging about it +[-ControlStructures::ProhibitUnlessBlocks] + +# The following only apply to modules +[-Modules::RequireVersionVar] +[-ErrorHandling::RequireCarping] + +# Tabs suck, no +[CodeLayout::ProhibitHardTabs] +allow_leading_tabs = 0 + +# For small regexes, no /x at the end is fine, 12 should be enough +[RegularExpressions::RequireExtendedFormatting] +minimum_regex_length_to_complain_about = 12 + +# These are kosher kthxbai +[ControlStructures::ProhibitPostfixControls] +allow = for if until unless + +# For POE, we do things like my $foo = $_[HEAP]; and thats OK +[Subroutines::RequireArgUnpacking] +allow_subscripts = 1 + +# For POD documentation, I don't care about required sections. +[Documentation::RequirePodSections] +lib_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT | SEE ALSO +script_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT | SEE ALSO + +# This is for POD documentation mainly. +[CodeLayout::ProhibitHardTabs] +allow_leading_tabs = 1 diff --git a/perl/.perltidyrc b/perl/.perltidyrc new file mode 100644 index 0000000..73c1753 --- /dev/null +++ b/perl/.perltidyrc @@ -0,0 +1,22 @@ +# cuddled elses pls +-ce +# indent 2 spaces +-i=2 +# for tokens with things like arrays, start the data next line down one indent in +-lp +# align closing tokens for things like arrays with the opening token +-cti=1 +# default, but spaces between multiple entries, none with one arg +-pt=1 +# line encoding +-ole=unix +# braces not on new line +-nsbl +# stack opening tokens, don't create a new line with one token, note no stacking of closing tokens +-sot +# no space before ;'s in for loops +-nsfs +# Make curly braces act more like the args param +-bbt=1 +# Trim qw whitespaces +-tqw diff --git a/perl/.profile.d/99-alias-perl.sh b/perl/.profile.d/99-alias-perl.sh new file mode 100644 index 0000000..c4a7ec2 --- /dev/null +++ b/perl/.profile.d/99-alias-perl.sh @@ -0,0 +1,2 @@ +# perl/.profile.d/99-alias-perl.sh +alias p=perl diff --git a/ruby/.gemrc b/ruby/.gemrc new file mode 100644 index 0000000..22fd901 --- /dev/null +++ b/ruby/.gemrc @@ -0,0 +1,2 @@ +install: --no-ri --no-rdoc +update: --no-ri --no-rdoc diff --git a/ruby/.maid/rules.rb b/ruby/.maid/rules.rb new file mode 100755 index 0000000..caddc11 --- /dev/null +++ b/ruby/.maid/rules.rb @@ -0,0 +1,63 @@ +#!/usr/bin/env ruby +#-*-mode: Ruby; coding: utf-8;-*- +require 'time' + +Maid.rules do + RUN_TIME = Time.now + DAY_SECONDS = 60 * 60 * 24 + WEEK = DAY_SECONDS * 7 + ONE_WEEK_AGO = (RUN_TIME - WEEK) + TWO_WEEKS_AGO = (RUN_TIME - WEEK * 2) + THREE_MONTHS_AGO = (RUN_TIME - (DAY_SECONDS * 93)) + + # Nuke crap > say 2 weeks should be fine. + def clean_download_dir + dir('~/Downloads/*').each do |path| + trash path if File.mtime(path) < TWO_WEEKS_AGO + end + end + + case %x/uname -s/.chomp + when 'Darwin' + rule '/Library/Caches/Homebrew/' do + dir('/Library/Caches/Homebrew/*.tar.*').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('/Library/Caches/Homebrew/*.tgz').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('/Library/Caches/Homebrew/*.tbz').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('/Library/Caches/Homebrew/*.bz2').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('/Library/Caches/Homebrew/*.gz').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('/Library/Caches/Homebrew/*.xz').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + end + + rule '~/Downloads' do + clean_download_dir + end + + rule '~/Library/Caches' do + dir('~/Library/Caches/Google/Chrome/Default/Cache/*').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('~/Library/Caches/Google/Chrome/PnaclTranslationCache/*').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + dir('~/Library/Caches/Firefox/Profiles/*.default/Cache/*').each do |path| + trash path if File.mtime(path) < THREE_MONTHS_AGO + end + end + when 'Linux' + rule 'Clean Download dir' do + clean_download_dir + end + end +end diff --git a/ruby/.profile.d/99-alias-ruby.sh b/ruby/.profile.d/99-alias-ruby.sh new file mode 100644 index 0000000..c2d08aa --- /dev/null +++ b/ruby/.profile.d/99-alias-ruby.sh @@ -0,0 +1,2 @@ +# ruby/.profile.d/99-alias-ruby.sh +alias r=ruby diff --git a/ruby/.pryrc b/ruby/.pryrc new file mode 100644 index 0000000..b30361d --- /dev/null +++ b/ruby/.pryrc @@ -0,0 +1,19 @@ +#-*-mode: Ruby; coding: utf-8;-*- + +Pry.config.prompt = [ + proc {|obj, nesting, _| + nesting == 0 ? "#{obj}> " : "#{obj}:#{nesting}> " + }, + proc {''} + ] + +def load_pry_debugstuff + if Gem::Specification::find_all_by_name('pry-debugger').size > 0 + require 'pry-debugger' + Pry.commands.alias_command 'c', 'continue' + Pry.commands.alias_command 's', 'step' + Pry.commands.alias_command 'n', 'next' + end +end + +load_pry_debugstuff diff --git a/tmux/.profile.d/20-functions-tmux.sh b/tmux/.profile.d/20-functions-tmux.sh new file mode 100644 index 0000000..b43c3c1 --- /dev/null +++ b/tmux/.profile.d/20-functions-tmux.sh @@ -0,0 +1,11 @@ +# tmux/.profile.d/20-functions-tmux.sh +t +{ + if [ -z "$1" ]; then + echo "Supply a tmux session name to connect to/create" + else + tmux has-session -t "$1" 2>/dev/null + [ $? != 0 ] && tmux new-session -d -s "$1" + tmux attach-session -d -t "$1" + fi +} diff --git a/tmux/.profile.d/99-alias-tmux.sh b/tmux/.profile.d/99-alias-tmux.sh new file mode 100644 index 0000000..1b98ec8 --- /dev/null +++ b/tmux/.profile.d/99-alias-tmux.sh @@ -0,0 +1,2 @@ +# tmux/.profile.d/99-alias-tmux.sh +alias tls='tmux ls' diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf new file mode 100644 index 0000000..0095010 --- /dev/null +++ b/tmux/.tmux.conf @@ -0,0 +1,160 @@ +# Setup utf8 by default and vi mode +set-window-option -g utf8 on +set-window-option -g mode-keys vi +set-window-option -g aggressive-resize on + +set-option -g default-command zsh +set-option -g default-terminal 'xterm-256color' + +# Status line options, mainly coloring +set-window-option -g window-status-bg colour6 +set-window-option -g window-status-fg black +set-window-option -g window-status-current-bg white + +# Status line options +set-option -g status-bg black +set-option -g status-fg colour7 +set-option -g status-left-length 24 +set-option -g status-left '' +set-option -g status-right-length 13 +set-option -g status-right "%a %H:%M:%S" +set-option -g status-interval 7 +set-option -g status-utf8 on + +# Pane border options, mimics the status line coloring +set-option -g pane-border-bg colour15 +set-option -g pane-border-fg colour82 +set-option -g pane-active-border-bg colour15 +set-option -g pane-active-border-fg colour2 + +# Alert related things +set-option -g visual-activity on +set-option -g visual-bell on +set-option -g message-bg colour7 +set-option -g message-fg black + +# Pass through the window title and display it automatically on changes. +set-option -g set-titles on +set-option -g set-titles-string '#T' +set-window-option -g automatic-rename on + +# Key rebinding to make things more au naturalle +bind-key R \ + source-file ~/.tmux.conf \;\ + display 'reloaded tmux config' + +# Log pane output to a file, save with an iso8601 datestamp +bind-key o \ + pipe-pane -o "cat >> $HOME/tmux-`iso8601`.log" \;\ + set-window-option window-status-current-fg green \; + +bind-key O \ + pipe-pane \;\ + set-window-option window-status-current-fg default \; + +bind-key N new-session -t default + +# Using s for synchronizing panes, means that s for choosing sessions +# is now e +unbind-key s # interactive select sessions +bind-key e choose-tree + +# (un)synchronize panes with prefix-s +bind-key s \ + if-shell \ + "tmux show-window-options | grep 'synchronize-panes on'" \ + "set-window-option window-status-current-bg colour7; \ + set-window-option pane-active-border-fg colour2; \ + set-window-option pane-active-border-bg colour15; \ + set-window-option synchronize-panes off; \ + display 'synchronization off'" \ + "set-window-option window-status-current-bg red; \ + set-window-option pane-active-border-fg red; \ + set-window-option pane-active-border-bg colour15; \ + set-window-option synchronize-panes on; \ + display 'synchronizing'" + +# same thing as ^ so it sets up things if we were started with +# something else that set synchronization. +if-shell \ + "tmux show-window-options | grep 'synchronize-panes on'" \ + "set-window-option window-status-current-bg red; \ + set-window-option pane-active-border-fg yellow; \ + set-window-option pane-active-border-bg red" + +# Setup splits to be less annoying +bind-key \ split-window -h +bind-key - split-window -v + +# vi keybindings for pane navigation +bind-key k select-pane -U +bind-key j select-pane -D +bind-key h select-pane -L +bind-key l select-pane -R + +# Make it so that I can detach/etc while holding control down, +# PURE LAZY +bind-key C-d detach +bind-key C-n next-window +bind-key C-p previous-window + +bind-key C-k select-pane -U +bind-key C-j select-pane -D +bind-key C-h select-pane -L +bind-key C-l select-pane -R + +# Non confirming kill pane plskthxbai +bind-key x kill-pane + +# In case something I run exits straight away, i'd like to know about it. +set-option -g set-remain-on-exit on + +# Lets change the prefix key so we don't clobber emacs back one char key +unbind-key C-b + +# hacky, but C-\ isn't used by anything overly important in emacs +set-option -g prefix 'C-\' + +# two C-\'s == C-\, if i need it, likely not +bind 'C-\' send-prefix + +# Delay in sending things is dumb +set-option -s escape-time 1 + +# so we can scroll the mouse, select panes, etc... +set-window-option -g mode-mouse on +set-window-option -g mouse-select-pane on +set-window-option -g mouse-resize-pane on +set-window-option -g mouse-select-window on + +# Mouse mode can be stupid at times, so make it toggleable. +bind-key m \ + if-shell \ + "tmux show-window-options | grep 'mode-mouse on'" \ + "set-window-option mode-mouse off; \ + set-window-option mouse-select-pane off; \ + set-window-option mouse-resize-pane off; \ + set-window-option mouse-select-window off; \ + display 'Mouse modes off'" \ + "set-window-option mode-mouse on; \ + set-window-option mouse-select-pane on; \ + set-window-option mouse-resize-pane on; \ + set-window-option mouse-select-window on; \ + display 'Mouse modes on'" + +# Assume linux for things, load osx stuff only on osx +bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer" +bind C-y run "tmux save-buffer - | xclip -i" + +# Linux specific. Now that I installed rainbarf on things, why not use it. +if-shell 'test "$(uname)" = "Linux"' \ + "set-option -g status-right-length 55; \ + set-option -g status-right '#(rainbarf --bright --width 25) %a %H:%M:%S'; " + +# osx specific +# Have to modify default command so I can ssh in. +# that and rainbarf output is 42 chars long (utf8) but helpful. +if-shell 'test "$(uname)" = "Darwin"' \ + "set-option -g default-command 'reattach-to-user-namespace -l zsh'; \ + set-option -g status-right-length 55; \ + set-option -g status-right '#(rainbarf --remaining --bolt --bright --width 25) %a %H:%M:%S'; " diff --git a/vim/.vimrc b/vim/.vimrc new file mode 100644 index 0000000..054681a --- /dev/null +++ b/vim/.vimrc @@ -0,0 +1,25 @@ +set nocompatible +set backspace=indent,eol,start +set history=50 " keep 50 lines of command line history +set ruler " show the cursor position all the time +set showcmd " display incomplete commands +set incsearch " do incremental searching +map Q gq +if &t_Co > 2 || has("gui_running") + syntax on + set hlsearch +endif +if has("autocmd") + filetype plugin indent on + augroup vimrcEx + au! + autocmd FileType text setlocal textwidth=78 + autocmd BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal g`\"" | + \ endif + + augroup END +else + set autoindent " always set autoindenting on +endif " has("autocmd") diff --git a/x/.Xdefaults b/x/.Xdefaults new file mode 100644 index 0000000..4773eef --- /dev/null +++ b/x/.Xdefaults @@ -0,0 +1,17 @@ +! urxvt generalish stuff +! +urxvt*termName: rxvt-256color +urxvt*font: xft:menlo:size=12:antialias=true +urxvt*perl-ext-common: default,matcher +urxvt*jumpScroll: true +urxvt*cursorColor: pink +urxvt*loginShell: true +urxvt*scrollBar: true +urxvt*scrollstyle: next +urxvt*scrollBar_right: true +urxvt*scrollTtyOutput: false +urxvt*cursorBlink: true +urxvt*saveLines: 10000 +urxvt*urlLauncher: /usr/bin/google-chrome +urxvt*matcher.button: 1 +urxvt*allowWindowOps: true diff --git a/x/.Xmodmap b/x/.Xmodmap new file mode 100644 index 0000000..2153f8b --- /dev/null +++ b/x/.Xmodmap @@ -0,0 +1 @@ +pointer = 3 2 1 4 5 diff --git a/x/.Xresources b/x/.Xresources new file mode 100644 index 0000000..ffb58ee --- /dev/null +++ b/x/.Xresources @@ -0,0 +1,41 @@ +#define brightblack #ffffff +#define normblack #f9f9f9 +#define normgreen #00cc33 +#define brightgreen #00cc99 +#define normblue #f00033 +#define brightblue #0099ff +#define normcyan #66ccff +#define brightcyan #66ccff +#define normwhite #060606 +#define brightwhite #000000 +#define normyellow #ffcc33 +#define brightyellow #ffcc33 +#define normred #ff3300 +#define brightred #ff3300 +#define normmagenta #ff66ff +#define brightmagenta #ff66ff + +*background: normblack +*foreground: normwhite +*fading: 40 +*fadeColor: brightblack +*cursorColor: brightcyan +*pointerColorBackground: #3f3f3f +*pointerColorForeground: #f3f3f3 + +*color0: #090909 +*color1: #f00000 +*color2: normgreen +*color3: normyellow +*color4: #0066ff +*color5: normmagenta +*color6: normcyan +*color7: #c8c8c8 +*color8: #888888 +*color9: #f00033 +*color10: brightgreen +*color11: brightyellow +*color12: #0099ff +*color13: brightmagenta +*color14: brightcyan +*color15: #f9f9f9 diff --git a/x/.profile.d/11-x-modmap.sh b/x/.profile.d/11-x-modmap.sh new file mode 100644 index 0000000..1baa1a0 --- /dev/null +++ b/x/.profile.d/11-x-modmap.sh @@ -0,0 +1,6 @@ +# x/.profile.d/11-x-modmap.sh +# x/.profile.d/11-x-modmap.sh +modmap +{ + [ -f "${HOME}/.Xmodmap" ] && xmodmap "${HOME}/.Xmodmap" +} diff --git a/zsh/.zprofile b/zsh/.zprofile new file mode 100644 index 0000000..f348144 --- /dev/null +++ b/zsh/.zprofile @@ -0,0 +1,9 @@ +emulate sh +source ~/.profile +emulate zsh + +# zsh does this differently +login_shell() +{ + [[ -o login ]] +} diff --git a/zsh/.zshrc b/zsh/.zshrc new file mode 100644 index 0000000..5fa0a29 --- /dev/null +++ b/zsh/.zshrc @@ -0,0 +1,141 @@ +#-*-mode: Shell-script; coding: utf-8;-*- +# zsh specific global aliases +alias -g silent="> /dev/null 2>&1" +alias -g noerr="2> /dev/null" +alias -g stdboth="2>&1" + +# mainly for firefox, because it can suck up the cycles, but not when +# in a SIGSTOP state you can't use any power then firefox. +alias -g sigcont='kill -CONT ' +alias -g sigstop='kill -STOP ' + +# Keybindings, what few there are. +bindkey -v +bindkey '^P' push-line # Saves the current line and returns to it afterwards. + +# General history options +export HISTSIZE=5000 +export SAVEHIST=${HISTSIZE} +export HISTFILE=~/.zsh_history + +# I like my options +setopt append_history +setopt extended_history +setopt hist_reduce_blanks +setopt hist_no_store +setopt hist_ignore_dups +setopt histignorespace +setopt no_hist_beep +setopt no_list_beep +setopt share_history +setopt inc_append_history +setopt auto_menu +setopt bash_auto_list + +# Options that don't need to be set. +unsetopt bad_pattern # No, don't warn me on bad file patterns kthxbai. + +# The rest of the story (tm) (c) (r) in option settings. +setopt equals +setopt notify +setopt auto_cd +setopt glob_dots +setopt print_exit_value # I love you zsh for this, print out non zero exits. + +other_term() +{ + case $TERM in + *xterm*|*rxvt*|(dt|k|e)term) + print -Pn "\e]2;%~\a" + ;; + sun-cmd) + print -Pn "\e]l%~\e\\" + ;; + *) + ;; + esac +} + +chpwd() +{ + [[ -o interactive ]] || return + case $TERM in + eterm-color) # getting emacs terminal to not be annoying... sucks + print -Pn "" + ;; + *) + if [[ $SSH_TTY != '' ]]; then + case $ORIG_TERM in + eterm-color) + print -Pn "" + ;; + *) + other_term + ;; + esac + fi + ;; + esac +} + +# Needs to be reviewed a bit. +zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' +zstyle ':completion:*:*:*:*:processes' force-list always + +# No need to setup ssh known host parsing as root, just regular users. +# This is pretty old using compctl, need to update eventually. + +if [[ "$LOGNAME" != "root" ]]; then + zmodload zsh/mathfunc + if [[ -f "$HOME/.ssh/known_hosts" ]]; then + hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*}) + zstyle ':completion:*:(ssh|scp|cssh):*' hosts $hosts + zstyle ':completion:*:*:*:hosts-host' ignored-patterns '|1|*' loopback localhost + fi + zstyle ':completion:::complete*' use-cache 1 + + # This really should be closer to the definition of extract. + compctl -g '*.tar.bz2 *.tbz2 *.tbz *.tar.gz *.tgz *.bz2 *.gz *.jar *.zip *.rar *.tar *.Z *.tZ *.tar.Z' + -g '*(-/)' extract +fi + +# More history options for newer zsh versions +setopt share_history +setopt hist_save_no_dups +setopt hist_find_no_dups +setopt hist_no_functions +setopt hist_expire_dups_first + +bindkey ' ' magic-space # Complete spaces too dammit, i'm lazy. + +alias edirs='ls -d **/*(/^F)' # empty directories +zstyle ':completion:*:*:kill:*' menu yes select +zstyle ':completion:*:kill:*' force-list always +zstyle ':completion:*:kill:*:processes' command "ps x" +zstyle ':completion:*' menu select=2 + +autoload -U compinit +autoload -U colors && colors +autoload -Uz vcs_info + +bindkey -e + +local userat="%{$fg[blue]%}%n%(!.%{$fg[red]%}.%{$fg[blue]%})%{$reset_color%}%B@%b%{$fg[blue]%}%m%b" +local pwd="%B%~%b" +local userchar="%(!.#.$)" + +zstyle ':vcs_info:*' enable git +zstyle ':vcs_info:*' check-for-changes true +setopt prompt_subst +precmd() +{ + vcs_info +} + +local branch=" %{$fg[green]%}%b%c%u%{$fg[green]%}%{$reset_color%}" +zstyle ':vcs_info:*' formats "$branch" +zstyle ':vcs_info:*' actionformats "$branch (%a)" +zstyle ':vcs_info:*' stagedstr "%{$fg[yellow]%}*" +zstyle ':vcs_info:*' unstagedstr "%{$fg[red]%}*" +PROMPT="$userat:$pwd\${vcs_info_msg_0_}$userchar "