Compare commits

..

No commits in common. "c9e8e938b69d9bf0ac79368bb8511461c27af327" and "305b8679c884bf10b4a475a57d0b0c4837b8d5c4" have entirely different histories.

4 changed files with 100 additions and 241 deletions

View File

@ -1,6 +1,12 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'optparse' #/ Usage: dotlinker <command>
#/
#/ list List files to link
#/ update Update dotfiles repo
#/ symlink Symlink all files
#/ unsymlink Unsymlink all files
require 'pathname' require 'pathname'
require 'fileutils' require 'fileutils'
@ -23,6 +29,10 @@ module ShellHelpers
"\033[0;#{COLOR_CODES[color] + 30}m#{str}\033[0m" "\033[0;#{COLOR_CODES[color] + 30}m#{str}\033[0m"
end end
def say_help
exec "grep ^#/<'#{__FILE__}'|cut -c4-"
end
def say(message, color = :default) def say(message, color = :default)
$stdout.print(colorify_string(message, color)) $stdout.print(colorify_string(message, color))
$stdout.flush $stdout.flush
@ -125,7 +135,7 @@ module FileHelpers
elsif destination.exist? elsif destination.exist?
say_status(:conflict, "#{destination} exists", :red) say_status(:conflict, "#{destination} exists", :red)
if options[:force] || collision_accepted?(destination) if collision_accepted?(destination)
FileUtils.rm_r(destination, force: true) FileUtils.rm_r(destination, force: true)
FileUtils.ln_s(source, destination, force: true) FileUtils.ln_s(source, destination, force: true)
end end
@ -137,17 +147,25 @@ module FileHelpers
end end
end end
module GitHelpers
extend self
def git_pull
say_status(:git, "Pulling #{`git config --get remote.origin.url`}", :green)
system 'git pull'
end
end
class Linker class Linker
include GitHelpers
include FileHelpers include FileHelpers
include ShellHelpers include ShellHelpers
VERSION = '0.2.1'.freeze VERSION = '0.1.0'.freeze
LINKDIR_FILENAME = '.linkdir'.freeze LINKDIR_FILENAME = '.linkdir'.freeze
attr_reader :options def git_dir
@git_dir ||= Pathname.new(File.dirname(__FILE__)).realpath
def initialize(options = {})
@options = options
end end
def home_dir def home_dir
@ -158,6 +176,10 @@ class Linker
@repo_dir ||= Pathname.new(File.dirname(__FILE__)).join('home').realpath @repo_dir ||= Pathname.new(File.dirname(__FILE__)).join('home').realpath
end end
def update
inside(git_dir) { git_pull }
end
def each_file def each_file
skip_dirs = [] skip_dirs = []
@ -184,7 +206,7 @@ class Linker
def symlink_all def symlink_all
each_file do |absolute_path, home_path| each_file do |absolute_path, home_path|
ln_s(absolute_path, home_path, options) ln_s(absolute_path, home_path)
end end
end end
@ -195,37 +217,24 @@ class Linker
end end
end end
COMMANDS = ['list', 'update', 'link', 'unlink'].freeze COMMANDS = ['list', 'update', 'symlink', 'unsymlink'].freeze
options = {}
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} <command> [options]"
opts.separator ''
opts.separator 'Commands:'
opts.separator 'list List files to link'
opts.separator 'link Symlink all files'
opts.separator 'unlink Unsymlink all files'
opts.separator ''
opts.separator 'Options:'
opts.on('-f', '--force', 'Force overwrite all files') { |force| options[:force] = force }
opts.on('-v', '--version', 'Show version information') { |_| ShellHelpers.say(Linker::VERSION); exit(0) }
end
opt_parser.parse!
command = ARGV.pop command = ARGV.pop
if command.nil? || !COMMANDS.include?(command) if command.nil? || !COMMANDS.include?(command)
ShellHelpers.say(opt_parser.help) ShellHelpers.say_help
else else
linker = Linker.new(options) linker = Linker.new
case command case command
when 'list' when 'list'
linker.list_all linker.list_all
when 'link' when 'update'
linker.update
when 'symlink'
linker.symlink_all linker.symlink_all
when 'unlink' when 'unsymlink'
linker.unsymlink_all linker.unsymlink_all
else
ShellHelpers.say_help
end end
end end

View File

@ -22,8 +22,3 @@
prompt = false prompt = false
[help] [help]
autocorrect = 1 autocorrect = 1
[filter "lfs"]
process = git-lfs filter-process
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f

View File

@ -1,223 +1,78 @@
################################################################################ # status bar
#### Unbreak things set -g status-right-length 20
set -g status-right '#[fg=red]#H#[fg=green]:#[fg=white]#S #[fg=green]][#[default]'
set -g status-left ''
# Prevent tmux from messing up keybindings and colors. # default statusbar colors
# This is witchcraft, I have no explanation for the following commands. set -g status-fg white
set-option -g xterm-keys on set -g status-bg default
set-window-option -g xterm-keys on set -g status-attr bright
set-option -g default-terminal "xterm-256color"
# Prevent tmux from waiting half a second before processing the ESC key, see: # default window title colors
# http://unix.stackexchange.com/a/25638/176805 set-window-option -g window-status-fg white
set-option -s escape-time 0 set-window-option -g window-status-bg default
set-window-option -g window-status-attr dim
# Enable proper mouse support: # active window title colors
# http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/ set-window-option -g window-status-current-fg white
set-option -g mouse on set-window-option -g window-status-current-bg default
bind-key m set-option -g mouse on set-window-option -g window-status-current-attr bright
bind-key M set-option -g mouse off
# The following line prevents a weird OS X problem that otherwise # C-b is not acceptable -- Vim uses it
# keeps the "open" command from working (and has several other # set-option -g prefix C-a
# undesirable properties; see issue #120). For more details on the # bind-key C-a last-window
# issue, see [1]-[5].
#
# The exact version of the solution below is the only way I have found
# to satisfy all of the following properties:
#
# * It fixes the problem, i.e. "open" works correctly.
#
# * When opening a new window in tmux, the window name is correctly
# set to zsh initially. It does not briefly flash
# "reattach-to-user-namespace", and it does not display
# "/usr/local/bin/zsh" either.
#
# * The "automatic-rename" property is still set to "on" in new tmux
# windows, meaning that if you run another program, the window name
# will change to reflect that (unless you manually rename the
# window).
#
# * Exiting the shell (e.g. with Control+D) will immediately kill the
# tmux window instead of dropping you into another shell.
#
# * It works for all shells, and doesn't hardcode any particular one.
#
# * It still works when reattach-to-user-namespace is unavailable.
#
# Yes, it's horrible. I think we can all agree on that, no need to
# point it out.
#
# Unfortunately, tmux appears to be remarkably unintelligent when it
# comes to determining the string to show as the window title.
# Basically, about as unintelligent as shebang parsing, and anyone
# involved in the virtualenv-can't-handle-spaces fiasco will know
# that's pretty darn unintelligent. In particular, it grabs characters
# literally from the beginning of the command string until it hits a
# space, then discards until the first slash, if there is one. This
# means it's impossible to quote the executable name, so if your shell
# has spaces in its name, you're screwed. Making this whole fiasco
# work for paths with double quotes in it is an exercise in futility,
# I think.
#
# [1]: http://superuser.com/q/834525/326239
# [2]: http://www.economyofeffort.com/2013/07/29/reattach-to-user-namespace-the-fix-for-your-tmux-in-os-x-woes/
# [3]: https://www.elmund.io/osx/2015/07/10/open-command-in-osx-tmux/
# [4]: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
# [5]: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/issues/10
run-shell 'command -v reattach-to-user-namespace > /dev/null && tmux set-option -g default-command "$SHELL -c \"reattach-to-user-namespace -l \\\"$(basename "$SHELL")\\\"\"" || true' # Start numbering at 1
set -g base-index 1
################################################################################ # Allows for faster key repetition
#### Keybindings set -s escape-time 0
# Use ` instead of C-b as prefix key, see: # Rather than constraining window size to the maximum size of any client
# http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/ # connected to the *session*, constrain window size to the maximum size of any
unbind-key C-b # client connected to *that window*. Much more reasonable.
set-option -g prefix ` setw -g aggressive-resize on
bind-key ` send-prefix
# Force tmux to use Emacs keybindings, see: # Allows us to use C-a a <command> to send commands to a TMUX session inside
# http://stackoverflow.com/q/18240683/3538165 # another TMUX session
# http://stackoverflow.com/a/18247437/3538165 bind-key a send-prefix
set-option -g status-keys emacs
set-window-option -g mode-keys emacs
# Turn off repeatability for moving between panes. Otherwise, if you split # Activity monitoring
# horizontally and switch panes, you will have to wait for the 'repeat period' setw -g monitor-activity on
# to expire before you can use <Up> and <Down> to page through shell history. set -g visual-activity on
#
# Doing it this way instead of using 'set-option -g repeat-time 0' makes it
# so that Control+Arrows and Meta+Arrows (for resizing panes) are still
# repeatable.
#
# See: http://superuser.com/a/325579/326239
bind-key Up select-pane -U
bind-key Down select-pane -D
bind-key Left select-pane -L
bind-key Right select-pane -R
# Keybinding for reloading .tmux.conf. # Highlight active window
bind-key R source-file ~/.tmux.conf set-window-option -g window-status-current-bg red
# Keybinding for swapping the current and marked windows. # VI keybindings please
bind-key \ swap-window setw -g mode-keys vi
# Keybindings for swapping adjacent windows. # VI for splitting
bind-key < swap-window -t -1 bind s split-window -v
bind-key > swap-window -t +1 bind v split-window -h
# Keybinding for inserting a window. # Vi copypaste mode
# Adapted from http://superuser.com/a/704551/326239 set-window-option -g mode-keys vi
bind-key I command-prompt -p 'Insert window at:' ' \ bind-key -T copy-mode-vi 'v' begin-selection
run-shell " \ bind-key -T copy-mode-vi 'y' copy-selection
if tmux select-window -t %1; then \
tmux new-window -a; \
tmux swap-window -s %1 -t \$((%1+1)); \
else \
tmux new-window; \
tmux move-window -t %1; \
fi; \
tmux select-window -t #{window_id}; \
tmux select-window -t %1; \
"'
################################################################################ # hjkl pane traversal
#### Status bar bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# The following code is adapted from: # reload config
# https://coderwall.com/p/trgyrq/make-your-tmux-status-bar-responsive bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# It provides the same appearance as https://github.com/powerline/powerline,
# but sidesteps the environment/configuration hell which that project
# introduces.
# Format to display on the left-hand side of the status bar. # auto window rename
# Note that the conditional #{?cond,true,false} operator does not do any set-window-option -g automatic-rename
# fancy parsing, so you can't have literal commas in the conditions --
# this will cause the conditions to be split up. So we have to use multiple
# style #[attr=value] directives.
set-option -g status-left '#{?client_prefix,#[fg=colour254]#[bg=colour31],#[fg=colour16]#[bg=colour254]#[bold]} #{=80:session_name} #{?client_prefix,#[fg=colour31],#[fg=colour254]}#[bg=colour234,nobold] '
# Maximum length of the format displayed on the left-hand side. # color
# Since the maximum length of the session name is limited in the above set -g default-terminal "screen-256color"
# format string, this number is unimportant -- it just needs to be a
# bit larger than what is allocated for the session name, to allow for
# the surrounding characters.
set-option -g status-left-length 90
# Format to display on the right-hand side of the status bar. # Pane resizing
set-option -g status-right '#{?mouse,#[fg=colour254]#[bg=colour31],#[fg=colour244,bg=colour234]} Mouse #[fg=colour254,bg=colour234] #H' bind-key J resize-pane -D 10
bind-key K resize-pane -U 10
# Format to display for the current window. bind-key H resize-pane -L 10
set-option -g window-status-current-format '#[fg=colour117,bg=colour31] #{window_index}#{window_flags} #[fg=colour231,bold]#(tmux display-message -p "#{pane_current_path}" | sed "s#$HOME#~#g") #{?#{m:*#{b:SHELL}*, #{pane_current_command}},| #{pane_current_command} }#[fg=colour31,bg=colour234,nobold]' bind-key L resize-pane -R 10
# Format to display for other windows.
set-option -g window-status-format '#[fg=colour244,bg=colour234]#{window_index}#{window_flags} #[fg=colour249]#(tmux display-message -p "#{pane_current_path}" | sed "s#$HOME#~#g") #{?#{m:*#{b:SHELL}*, #{pane_current_command}},| #{pane_current_command} }'
# Background color for parts of the status bar not specified by the above
# formats. For instance, the empty space to the right, and the single
# spaces between instances of window-status-format.
set-option -g status-bg colour234
# Inhibit the default styling for windows with unseen activity, which
# looks blatantly incorrect with the "powerline" theme we are trying to
# emulate.
set-window-option -g window-status-activity-attr none
# Update the status bar every second, instead of the default 15(!)
# seconds. It doesn't look like it's possible to update more than
# once per second, unfortunately.
set-option -g status-interval 1
################################################################################
#### Appearance
# Attempt to set the title of the terminal emulator.
set-option -g set-titles on
set-option -g set-titles-string '#{session_name} - #{window_name}'
# Show an indicator in the status bar on windows with unseen activity.
set-option -g monitor-activity on
# Make the borders of the current pane the same color as the borders
# of other panes. This is because the borders of the marked pane are
# *inverted*, and while different foreground colors in different parts
# of the frame are not too objectionable, different background colors
# look very bad.
set-option -g pane-active-border-style none
################################################################################
#### Miscellaneous
# When the current session is killed, switch to another session instead of
# detaching.
set-option -g detach-on-destroy off
# Show messages until they are dismissed, instead of for 750 milliseconds(!).
# Actually it is only for an hour, because it doesn't seem like you can turn
# off the time limit.
set-option -g display-time 36000000
# Open new windows in the same directory as the current pane.
bind-key c new-window -c "#{pane_current_path}"
# Automatically renumber windows when one is deleted, see:
# http://unix.stackexchange.com/a/51879/176805
set-option -g renumber-windows on
# Number windows and panes from 1, instead of 0; see:
# http://unix.stackexchange.com/a/35932/176805
set-option -g base-index 1
set-window-option -g pane-base-index 1
# Open new panes in the same directory as the current pane.
bind-key % split-window -h -c "#{pane_current_path}"
bind-key '"' split-window -v -c "#{pane_current_path}"
# Increase the scrollback buffer size from 2000 to a larger size, but
# not one so large that tmux begins to lag.
set-option -g history-limit 10000
################################################################################
#### Local overrides
if-shell "[[ -f ~/.tmux.local.conf ]]" "source ~/.tmux.local.conf"

View File

@ -1,7 +1,7 @@
ZSH=$HOME/.oh-my-zsh ZSH=$HOME/.oh-my-zsh
ZSH_THEME="cheetah" ZSH_THEME="cheetah"
plugins=(osx brew git github redis-cli ruby rbenv gem bundler sublime pass docker zsh-syntax-highlighting) plugins=(osx brew git github redis-cli ruby rbenv gem bundler sublime pass zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh