From 7829058f8e71c1cbb167aca228aba4f7d9950401 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Thu, 23 May 2013 13:17:40 +0400 Subject: [PATCH] FISH --- .gitignore | 3 + bin/brew-musthave | 3 + zsh/support/chmod_help.zsh => bin/chmod-help | 7 +- bin/dock-delay | 3 + bin/extract | 27 ++ bin/git-undo | 5 + bin/git-up | 47 +++ bin/git-wtf | 364 +++++++++++++++++++ bin/gitio | 33 ++ bin/show-colors | 6 + bin/subl | 1 + bin/vandal | 64 ---- fish/fish/completions/c.fish | 1 + fish/fish/completions/h.fish | 1 + fish/fish/completions/rake.fish | 17 + fish/fish/config.fish | 11 + fish/fish/functions/c.fish | 3 + fish/fish/functions/fish_prompt.fish | 20 + fish/fish/functions/fish_right_prompt.fish | 36 ++ fish/fish/functions/h.fish | 3 + fish/fish/includes/alias.fish | 49 +++ fish/fish/includes/path.fish | 10 + fish/fish/includes/ruby.fish | 8 + setup.sh | 3 +- zsh/functions/extract | 28 -- zsh/support/dock_delay.zsh | 3 - zsh/support/show_colors.zsh | 3 - 27 files changed, 655 insertions(+), 104 deletions(-) create mode 100755 bin/brew-musthave rename zsh/support/chmod_help.zsh => bin/chmod-help (74%) create mode 100755 bin/dock-delay create mode 100755 bin/extract create mode 100755 bin/git-undo create mode 100755 bin/git-up create mode 100755 bin/git-wtf create mode 100755 bin/gitio create mode 100755 bin/show-colors create mode 100755 bin/subl delete mode 100755 bin/vandal create mode 100644 fish/fish/completions/c.fish create mode 100644 fish/fish/completions/h.fish create mode 100644 fish/fish/completions/rake.fish create mode 100644 fish/fish/config.fish create mode 100644 fish/fish/functions/c.fish create mode 100644 fish/fish/functions/fish_prompt.fish create mode 100644 fish/fish/functions/fish_right_prompt.fish create mode 100644 fish/fish/functions/h.fish create mode 100644 fish/fish/includes/alias.fish create mode 100644 fish/fish/includes/path.fish create mode 100644 fish/fish/includes/ruby.fish delete mode 100644 zsh/functions/extract delete mode 100644 zsh/support/dock_delay.zsh delete mode 100644 zsh/support/show_colors.zsh diff --git a/.gitignore b/.gitignore index ea982b5..d16e86a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ vim/bundle/* vim/vim/* + +fish/fish/fish_history +fish/fish/fishd.* diff --git a/bin/brew-musthave b/bin/brew-musthave new file mode 100755 index 0000000..c8bb32a --- /dev/null +++ b/bin/brew-musthave @@ -0,0 +1,3 @@ +#!/bin/sh + +brew install autoconf automake cmake doxygen fish freetype git graphicsmagickwget htop-osx httperf jq libevent libspatialite memcached mysql nginx node openssl phantomjs postgis postgresql pyqt python python3 qt rbenv rbenv-vars readline redis riak sqlite the_silver_searcher tmux v8 diff --git a/zsh/support/chmod_help.zsh b/bin/chmod-help similarity index 74% rename from zsh/support/chmod_help.zsh rename to bin/chmod-help index 6537c3f..e7da105 100644 --- a/zsh/support/chmod_help.zsh +++ b/bin/chmod-help @@ -1,8 +1,6 @@ -# I'm just unable to remember this shit -# Taken from http://www.analysisandsolutions.com/code/chmod.htm +#!/bin/bash -chmod-help () { - echo "\ +echo "\ +---+-----+-------------------------+ | 0 | --- | no access | | 1 | --x | only execute | @@ -14,4 +12,3 @@ chmod-help () { | 7 | rwx | read, write and execute | +---+-----+-------------------------+\ " -} diff --git a/bin/dock-delay b/bin/dock-delay new file mode 100755 index 0000000..ce1c28b --- /dev/null +++ b/bin/dock-delay @@ -0,0 +1,3 @@ +#!/bin/bash + +defaults write com.apple.Dock autohide-delay -float $1 && killall Dock diff --git a/bin/extract b/bin/extract new file mode 100755 index 0000000..e360c34 --- /dev/null +++ b/bin/extract @@ -0,0 +1,27 @@ +#!/bin/bash + +# credit: http://nparikh.org/notes/zshrc.txt +# Usage: smartextract +# Description: extracts archived files / mounts disk images +# Note: .dmg/hdiutil is Mac OS X-specific. + +if [ -f $1 ]; then + case $1 in + *.tar.bz2) tar -jxvf $1 ;; + *.tar.gz) tar -zxvf $1 ;; + *.bz2) bunzip2 $1 ;; + *.dmg) hdiutil mount $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar -xvf $1 ;; + *.tbz2) tar -jxvf $1 ;; + *.tgz) tar -zxvf $1 ;; + *.zip) unzip $1 ;; + *.ZIP) unzip $1 ;; + *.pax) cat $1 | pax -r ;; + *.pax.Z) uncompress $1 --stdout | pax -r ;; + *.Z) uncompress $1 ;; + *) echo "'$1' cannot be extracted/mounted via smartextract()" ;; + esac +else + echo "'$1' is not a valid file" +fi diff --git a/bin/git-undo b/bin/git-undo new file mode 100755 index 0000000..602032d --- /dev/null +++ b/bin/git-undo @@ -0,0 +1,5 @@ +#!/bin/sh +# +# Undo your last commit, but don't throw away your changes + +git reset --soft HEAD^ diff --git a/bin/git-up b/bin/git-up new file mode 100755 index 0000000..2934e6d --- /dev/null +++ b/bin/git-up @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +last_commit = `git rev-parse HEAD`.chomp +system 'git pull --rebase' + +news = `git whatchanged #{last_commit}..HEAD` + +files = Hash.new do |hash, key| + hash[key] = { :status => [], :author => [] } +end +conflict = false +current_author = '' + +news.split("\n").each do |str| + am = str.match(/Author: (.*?) <.*/) + current_author = am[1] unless am.nil? + + fm = str.match(/^:.*?\.\.\. ([A-Z]+)\t(.*)/) + next if fm.nil? + + m, status, file = *fm + + files[file][:status] << status + files[file][:author] << current_author + + conflict = true if status.length > 1 +end + +files.each do |file, info| + color_code = case info[:status].first + when 'D' then 31 + when 'A' then 32 + else 33 + end + puts "\e[1m\e[#{color_code}m#{info[:status].first}\e[0m #{file} (\e[34m#{info[:author].uniq.join(', ')}\e[0m)" +end + +exit if conflict + +# Running bundle command if needed +system 'bundle' if files.keys.include?('Gemfile') + +# Migrating if schema has changed +if files.keys.include?('db/schema.rb') + system 'bundle exec rake db:migrate' + system 'git checkout db/schema.rb' # Reseting schema +end diff --git a/bin/git-wtf b/bin/git-wtf new file mode 100755 index 0000000..e407eae --- /dev/null +++ b/bin/git-wtf @@ -0,0 +1,364 @@ +#!/usr/bin/env ruby + +HELP = < +.git-wtfrc" and edit it. The config file is a YAML file that specifies the +integration branches, any branches to ignore, and the max number of commits to +display when --all-commits isn't used. git-wtf will look for a .git-wtfrc file +starting in the current directory, and recursively up to the root. + +IMPORTANT NOTE: all local branches referenced in .git-wtfrc must be prefixed +with heads/, e.g. "heads/master". Remote branches must be of the form +remotes//. +EOS + +COPYRIGHT = <. +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You can find the GNU General Public License at: http://www.gnu.org/licenses/ +EOS + +require 'yaml' +CONFIG_FN = ".git-wtfrc" + +class Numeric; def pluralize s; "#{to_s} #{s}" + (self != 1 ? "s" : "") end end + +if ARGV.delete("--help") || ARGV.delete("-h") + puts USAGE + exit +end + +## poor man's trollop +$long = ARGV.delete("--long") || ARGV.delete("-l") +$short = ARGV.delete("--short") || ARGV.delete("-s") +$all = ARGV.delete("--all") || ARGV.delete("-a") +$all_commits = ARGV.delete("--all-commits") || ARGV.delete("-A") +$dump_config = ARGV.delete("--dump-config") +$key = ARGV.delete("--key") || ARGV.delete("-k") +$show_relations = ARGV.delete("--relations") || ARGV.delete("-r") +ARGV.each { |a| abort "Error: unknown argument #{a}." if a =~ /^--/ } + +## search up the path for a file +def find_file fn + while true + return fn if File.exist? fn + fn2 = File.join("..", fn) + return nil if File.expand_path(fn2) == File.expand_path(fn) + fn = fn2 + end +end + +want_color = `git config color.wtf` +want_color = `git config color.ui` if want_color.empty? +$color = case want_color.chomp + when "true"; true + when "auto"; $stdout.tty? +end + +def red s; $color ? "\033[31m#{s}\033[0m" : s end +def green s; $color ? "\033[32m#{s}\033[0m" : s end +def yellow s; $color ? "\033[33m#{s}\033[0m" : s end +def cyan s; $color ? "\033[36m#{s}\033[0m" : s end +def grey s; $color ? "\033[1;30m#{s}\033[0m" : s end +def purple s; $color ? "\033[35m#{s}\033[0m" : s end + +## the set of commits in 'to' that aren't in 'from'. +## if empty, 'to' has been merged into 'from'. +def commits_between from, to + if $long + `git log --pretty=format:"- %s [#{yellow "%h"}] (#{purple "%ae"}; %ar)" #{from}..#{to}` + else + `git log --pretty=format:"- %s [#{yellow "%h"}]" #{from}..#{to}` + end.split(/[\r\n]+/) +end + +def show_commits commits, prefix=" " + if commits.empty? + puts "#{prefix} none" + else + max = $all_commits ? commits.size : $config["max_commits"] + max -= 1 if max == commits.size - 1 # never show "and 1 more" + commits[0 ... max].each { |c| puts "#{prefix}#{c}" } + puts grey("#{prefix}... and #{commits.size - max} more (use -A to see all).") if commits.size > max + end +end + +def ahead_behind_string ahead, behind + [ahead.empty? ? nil : "#{ahead.size.pluralize 'commit'} ahead", + behind.empty? ? nil : "#{behind.size.pluralize 'commit'} behind"]. + compact.join("; ") +end + +def widget merged_in, remote_only=false, local_only=false, local_only_merge=false + left, right = case + when remote_only; %w({ }) + when local_only; %w{( )} + else %w([ ]) + end + middle = case + when merged_in && local_only_merge; green("~") + when merged_in; green("x") + else " " + end + print left, middle, right +end + +def show b + have_both = b[:local_branch] && b[:remote_branch] + + pushc, pullc, oosync = if have_both + [x = commits_between(b[:remote_branch], b[:local_branch]), + y = commits_between(b[:local_branch], b[:remote_branch]), + !x.empty? && !y.empty?] + end + + if b[:local_branch] + puts "Local branch: " + green(b[:local_branch].sub(/^heads\//, "")) + + if have_both + if pushc.empty? + puts "#{widget true} in sync with remote" + else + action = oosync ? "push after rebase / merge" : "push" + puts "#{widget false} NOT in sync with remote (you should #{action})" + show_commits pushc unless $short + end + end + end + + if b[:remote_branch] + puts "Remote branch: #{cyan b[:remote_branch]} (#{b[:remote_url]})" + + if have_both + if pullc.empty? + puts "#{widget true} in sync with local" + else + action = pushc.empty? ? "merge" : "rebase / merge" + puts "#{widget false} NOT in sync with local (you should #{action})" + show_commits pullc unless $short + end + end + end + + puts "\n#{red "WARNING"}: local and remote branches have diverged. A merge will occur unless you rebase." if oosync +end + +def show_relations b, all_branches + ibs, fbs = all_branches.partition { |name, br| $config["integration-branches"].include?(br[:local_branch]) || $config["integration-branches"].include?(br[:remote_branch]) } + if $config["integration-branches"].include? b[:local_branch] + puts "\nFeature branches:" unless fbs.empty? + fbs.each do |name, br| + next if $config["ignore"].member?(br[:local_branch]) || $config["ignore"].member?(br[:remote_branch]) + next if br[:ignore] + local_only = br[:remote_branch].nil? + remote_only = br[:local_branch].nil? + name = if local_only + purple br[:name] + elsif remote_only + cyan br[:name] + else + green br[:name] + end + + ## for remote_only branches, we'll compute wrt the remote branch head. otherwise, we'll + ## use the local branch head. + head = remote_only ? br[:remote_branch] : br[:local_branch] + + remote_ahead = b[:remote_branch] ? commits_between(b[:remote_branch], head) : [] + local_ahead = b[:local_branch] ? commits_between(b[:local_branch], head) : [] + + if local_ahead.empty? && remote_ahead.empty? + puts "#{widget true, remote_only, local_only} #{name} #{local_only ? "(local-only) " : ""}is merged in" + elsif local_ahead.empty? + puts "#{widget true, remote_only, local_only, true} #{name} merged in (only locally)" + else + behind = commits_between head, (br[:local_branch] || br[:remote_branch]) + ahead = remote_only ? remote_ahead : local_ahead + puts "#{widget false, remote_only, local_only} #{name} #{local_only ? "(local-only) " : ""}is NOT merged in (#{ahead_behind_string ahead, behind})" + show_commits ahead unless $short + end + end + else + puts "\nIntegration branches:" unless ibs.empty? # unlikely + ibs.sort_by { |v, br| v }.each do |v, br| + next if $config["ignore"].member?(br[:local_branch]) || $config["ignore"].member?(br[:remote_branch]) + next if br[:ignore] + local_only = br[:remote_branch].nil? + remote_only = br[:local_branch].nil? + name = remote_only ? cyan(br[:name]) : green(br[:name]) + + ahead = commits_between v, (b[:local_branch] || b[:remote_branch]) + if ahead.empty? + puts "#{widget true, local_only} merged into #{name}" + else + #behind = commits_between b[:local_branch], v + puts "#{widget false, local_only} NOT merged into #{name} (#{ahead.size.pluralize 'commit'} ahead)" + show_commits ahead unless $short + end + end + end +end + +#### EXECUTION STARTS HERE #### + +## find config file and load it +$config = { "integration-branches" => %w(heads/master heads/next heads/edge), "ignore" => [], "max_commits" => 5 }.merge begin + fn = find_file CONFIG_FN + if fn && (h = YAML::load_file(fn)) # yaml turns empty files into false + h["integration-branches"] ||= h["versions"] # support old nomenclature + h + else + {} + end +end + +if $dump_config + puts $config.to_yaml + exit +end + +## first, index registered remotes +remotes = `git config --get-regexp ^remote\.\*\.url`.split(/[\r\n]+/).inject({}) do |hash, l| + l =~ /^remote\.(.+?)\.url (.+)$/ or next hash + hash[$1] ||= $2 + hash +end + +## next, index followed branches +branches = `git config --get-regexp ^branch\.`.split(/[\r\n]+/).inject({}) do |hash, l| + case l + when /branch\.(.*?)\.remote (.+)/ + name, remote = $1, $2 + + hash[name] ||= {} + hash[name].merge! :remote => remote, :remote_url => remotes[remote] + when /branch\.(.*?)\.merge ((refs\/)?heads\/)?(.+)/ + name, remote_branch = $1, $4 + hash[name] ||= {} + hash[name].merge! :remote_mergepoint => remote_branch + end + hash +end + +## finally, index all branches +remote_branches = {} +`git show-ref`.split(/[\r\n]+/).each do |l| + sha1, ref = l.chomp.split " refs/" + + if ref =~ /^heads\/(.+)$/ # local branch + name = $1 + next if name == "HEAD" + branches[name] ||= {} + branches[name].merge! :name => name, :local_branch => ref + elsif ref =~ /^remotes\/(.+?)\/(.+)$/ # remote branch + remote, name = $1, $2 + remote_branches["#{remote}/#{name}"] = true + next if name == "HEAD" + ignore = !($all || remote == "origin") + + branch = name + if branches[name] && branches[name][:remote] == remote + # nothing + else + name = "#{remote}/#{branch}" + end + + branches[name] ||= {} + branches[name].merge! :name => name, :remote => remote, :remote_branch => "#{remote}/#{branch}", :remote_url => remotes[remote], :ignore => ignore + end +end + +## assemble remotes +branches.each do |k, b| + next unless b[:remote] && b[:remote_mergepoint] + b[:remote_branch] = if b[:remote] == "." + b[:remote_mergepoint] + else + t = "#{b[:remote]}/#{b[:remote_mergepoint]}" + remote_branches[t] && t # only if it's still alive + end +end + +show_dirty = ARGV.empty? +targets = if ARGV.empty? + [`git symbolic-ref HEAD`.chomp.sub(/^refs\/heads\//, "")] +else + ARGV.map { |x| x.sub(/^heads\//, "") } +end.map { |t| branches[t] or abort "Error: can't find branch #{t.inspect}." } + +targets.each do |t| + show t + show_relations t, branches if $show_relations || t[:remote_branch].nil? +end + +modified = show_dirty && `git ls-files -m` != "" +uncommitted = show_dirty && `git diff-index --cached HEAD` != "" + +if $key + puts + puts KEY +end + +puts if modified || uncommitted +puts "#{red "NOTE"}: working directory contains modified files." if modified +puts "#{red "NOTE"}: staging area contains staged but uncommitted files." if uncommitted + +# the end! diff --git a/bin/gitio b/bin/gitio new file mode 100755 index 0000000..30bae81 --- /dev/null +++ b/bin/gitio @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +# Usage: gitio URL [CODE] +# +# Turns a github.com URL +# into a git.io URL +# +# Created by @defunkt: +# https://gist.github.com/1209316 +# +# Copies the git.io URL to your clipboard. + +url = ARGV[0] +code = ARGV[1] + +if url !~ /^(https?:\/\/)?(gist\.)?github.com/ + abort "* github.com URLs only" +end + +if url !~ /^http/ + url = "https://#{url}" +end + +if code + code = "-F code=#{code}" +end + +output = `curl -i http://git.io -F 'url=#{url}' #{code} 2> /dev/null` +if output =~ /Location: (.+)\n?/ + puts $1 + `echo #$1 | pbcopy` +else + puts output +end diff --git a/bin/show-colors b/bin/show-colors new file mode 100755 index 0000000..fc556fa --- /dev/null +++ b/bin/show-colors @@ -0,0 +1,6 @@ +#!/bin/bash + +for code in $(seq -w 0 255) +do + printf "%03s: %bLorem ipsum dolor sit amet%b\n" "${code}" "\e[38;05;${code}m" "\e[m" +done diff --git a/bin/subl b/bin/subl new file mode 100755 index 0000000..38a7cd6 --- /dev/null +++ b/bin/subl @@ -0,0 +1 @@ +/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl diff --git a/bin/vandal b/bin/vandal deleted file mode 100755 index 1badf04..0000000 --- a/bin/vandal +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env ruby - -require 'fileutils' -require 'open-uri' -require 'yaml' - -BASE_DIR = File.join(File.dirname(__FILE__), '..', 'vim') -BUNDLE_DIR = File.join(BASE_DIR, 'bundle') -PACKAGES_FILE = File.join(BASE_DIR, 'packages.yml') - -ACTION = ARGV[0] -exit unless [nil, 'edit', 'install', 'update'].include?(ACTION) - -if ACTION == 'edit' - `subl #{PACKAGES_FILE}` - exit -end - -PACKAGES = (YAML.load_file(PACKAGES_FILE) || {}).map do |package| - package['dir'] = File.join(BUNDLE_DIR, package['dir']) - package -end -INSTALLED = Dir.entries(BUNDLE_DIR).delete_if{ |f| ['.', '..'].include?(f) } - -def install(meta) - `git clone git@github.com:#{meta['github']}.git #{meta['dir']} 2>/dev/null` - FileUtils.mv("#{meta['dir']}/.git", "#{meta['dir']}/_git") -end - -def update(meta) - FileUtils.mv("#{meta['dir']}/_git", "#{meta['dir']}/.git") - `cd #{meta['dir']} && git pull 2>/dev/null` - FileUtils.mv("#{meta['dir']}/.git", "#{meta['dir']}/_git") -end - -def remove(dir) - name = dir.split(?/).last.gsub(/\.-/, '_').split(?_).map(&:capitalize).join(' ') - puts "Removing #{name}" - FileUtils.rm_r(File.join(BUNDLE_DIR, dir)) -end - -# Removing packages -(INSTALLED - PACKAGES.map{ |b| b['dir'].split(?/).last }).each{ |b| remove(b) } - -PACKAGES.each do |meta| - if File.exist?(meta['dir']) - if ACTION != 'install' - puts "Updating #{meta['name']}" - update(meta) - else - puts "Using #{meta['name']}" - end - else - if ACTION != 'update' - puts "Installing #{meta['name']}" - install(meta) - else - puts "Using #{meta['name']}" - end - end -end - -puts -puts 'Done' diff --git a/fish/fish/completions/c.fish b/fish/fish/completions/c.fish new file mode 100644 index 0000000..5649786 --- /dev/null +++ b/fish/fish/completions/c.fish @@ -0,0 +1 @@ +complete -x -c c -a "(ls $PROJECTS)" diff --git a/fish/fish/completions/h.fish b/fish/fish/completions/h.fish new file mode 100644 index 0000000..8e1bc31 --- /dev/null +++ b/fish/fish/completions/h.fish @@ -0,0 +1 @@ +complete -x -c h -a "(ls $HOME)" diff --git a/fish/fish/completions/rake.fish b/fish/fish/completions/rake.fish new file mode 100644 index 0000000..36b1fdc --- /dev/null +++ b/fish/fish/completions/rake.fish @@ -0,0 +1,17 @@ +function __cache_or_get_rake_completion -d "Create rake completions" + mkdir -p "/tmp/rake_completion_cache_for_$USER" + set -l hashed_pwd (pwd | md5) + set -l rake_cache_file "/tmp/rake_completion_cache_for_$USER/$hashed_pwd" + + if not test -f "$rake_cache_file" + rake -T 2>&1 | sed -e "s/^rake \([a-z:_0-9!\-]*\).*#\(.*\)/\1 \2/" > "$rake_cache_file" + end + cat "$rake_cache_file" +end + +function __run_rake_completion + test -f rakefile; or test -f Rakefile; or test -f rakefile.rb; or test -f Rakefile.rb +end + +complete -x -c rake -a "(__cache_or_get_rake_completion)" -n __run_rake_completion + diff --git a/fish/fish/config.fish b/fish/fish/config.fish new file mode 100644 index 0000000..275d211 --- /dev/null +++ b/fish/fish/config.fish @@ -0,0 +1,11 @@ +set -U EDITOR vi + +set -x FISH $HOME/.config/fish +set -x DF $HOME/.dotfiles +set -x PROJECTS $HOME/Code + +set -x fish_greeting '' + +. $FISH/includes/alias.fish +. $FISH/includes/ruby.fish +. $FISH/includes/path.fish diff --git a/fish/fish/functions/c.fish b/fish/fish/functions/c.fish new file mode 100644 index 0000000..d5df8f1 --- /dev/null +++ b/fish/fish/functions/c.fish @@ -0,0 +1,3 @@ +function c + cd $PROJECTS/$argv[1] +end diff --git a/fish/fish/functions/fish_prompt.fish b/fish/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..c05d13e --- /dev/null +++ b/fish/fish/functions/fish_prompt.fish @@ -0,0 +1,20 @@ +function fish_prompt --description 'Write out the prompt' + set_color blue + printf (__fish_basedir) + if test -d .git + set_color magenta + __fish_git_need_commit + end + set_color normal + printf ' › ' +end + +function __fish_basedir + echo (pwd | rev | cut -d/ -f1 | rev) +end + +function __fish_git_need_commit + /usr/local/bin/git diff --stat 2>/dev/null | awk -F',' '/files? changed/ { lc += $2 + $3 } END { + if (lc > 100) printf " -- Y U NO COMMIT!? --" + }' +end diff --git a/fish/fish/functions/fish_right_prompt.fish b/fish/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..7af4f54 --- /dev/null +++ b/fish/fish/functions/fish_right_prompt.fish @@ -0,0 +1,36 @@ +function fish_right_prompt --description 'Write out the right prompt' + if test -d .git + __fish_git_unpushed + __fish_git_dirty + end +end + +function __fish_git_branch + echo (/usr/local/bin/git symbolic-ref HEAD 2>/dev/null | rev | cut -d/ -f1 | rev) +end + +function __fish_git_is_dirty + echo (/usr/local/bin/git status --porcelain) +end + +function __fish_git_dirty + if [ (__fish_git_is_dirty) ] + set_color red + else + set_color green + end + printf "%s" (__fish_git_branch) + set_color normal +end + +function __fish_git_is_unpushed + echo (/usr/local/bin/git cherry -v "@{upstream}" 2>/dev/null) +end + +function __fish_git_unpushed + if [ (__fish_git_is_unpushed) ] + set_color cyan + printf "✖ " + set_color normal + end +end diff --git a/fish/fish/functions/h.fish b/fish/fish/functions/h.fish new file mode 100644 index 0000000..79659d3 --- /dev/null +++ b/fish/fish/functions/h.fish @@ -0,0 +1,3 @@ +function h + cd $HOME/$argv[1] +end diff --git a/fish/fish/includes/alias.fish b/fish/fish/includes/alias.fish new file mode 100644 index 0000000..6590b4e --- /dev/null +++ b/fish/fish/includes/alias.fish @@ -0,0 +1,49 @@ +alias reload! ". $HOME/.config/fish/config.fish" +alias b "bundle exec" + +alias ll "ls -lah" +alias please "sudo" + +# Ruby & Rails +alias b "bundle exec" + +alias rails "bundle exec rails" +alias rake "bundle exec rake" +alias rspec "bundle exec rspec" +alias cap "bundle exec cap" +alias cucumber "bundle exec cucumber" + +alias mkbundle "bundle install --path vendor/gems" +alias ss "git up; bundle --quiet; bundle exec rake db:migrate" +alias rc "rails c" +alias rs "rails s" +alias rs1 "rails s -p3001" +alias rs2 "rails s -p3002" +alias fs "bundle exec foreman start" + +# Git +alias git "git-achievements" +alias gl "git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative" +alias gc "git ci -m" +alias ga "git add -u; git add .; git st" +alias gs "git st" +alias gd "git diff" +alias gp "git push" +alias gu "gut up" +alias gb "git br" + +# OSX +alias hidedesktop "defaults write com.apple.finder CreateDesktop -bool false; killall Finder" +alias showdesktop "defaults write com.apple.finder CreateDesktop -bool true; killall Finder" + +# Services start-ups and shut-downs +alias mysql-start="mysql.server start" +alias mysql-stop="mysql.server stop" +alias mysql-restart="mysql.server restart" + +alias postgres-start="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start" +alias postgres-stop="pg_ctl -D /usr/local/var/postgres stop -s -m fast" + +alias redis-start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist" +alias redis-stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist" +alias redis-restart="redis-stop; redis-start" diff --git a/fish/fish/includes/path.fish b/fish/fish/includes/path.fish new file mode 100644 index 0000000..b323d85 --- /dev/null +++ b/fish/fish/includes/path.fish @@ -0,0 +1,10 @@ +set -x PATH /usr/local/sbin $PATH +set -x PATH $HOME/.dotfiles/bin $PATH +set -x PATH $HOME/.rbenv/shims $PATH +set -x PATH /usr/local/share/npm/bin $PATH +set -x PATH /usr/local/share/python $PATH +set -x PATH ~/.dotfiles/bin $PATH +set -x PATH /usr/local/share/npm/bin $PATH +set -x PATH /usr/local/share/python $PATH +set -x PATH ~/.misc/git-achievements $PATH +set -x PATH /Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin $PATH diff --git a/fish/fish/includes/ruby.fish b/fish/fish/includes/ruby.fish new file mode 100644 index 0000000..4b586ea --- /dev/null +++ b/fish/fish/includes/ruby.fish @@ -0,0 +1,8 @@ +set -x RUBYOPT "-Ku" # Remove it after migration to 2.0 + +set -x RUBY_HEAP_MIN_SLOTS 800000 +set -x RUBY_HEAP_FREE_MIN 100000 +set -x RUBY_FREE_MIN 200000 +set -x RUBY_HEAP_SLOTS_INCREMENT 300000 +set -x RUBY_HEAP_SLOTS_GROWTH_FACTOR 1 +set -x RUBY_GC_MALLOC_LIMIT 79000000 diff --git a/setup.sh b/setup.sh index f49cb08..f8e3f44 100755 --- a/setup.sh +++ b/setup.sh @@ -2,8 +2,9 @@ ln -s ~/.dotfiles/git/gitconfig ~/.gitconfig ln -s ~/.dotfiles/git/gitignore ~/.gitignore -# ZSH +# ZSH and Fish ln -s ~/.dotfiles/zsh/zshrc ~/.zshrc +ln -s ~/.dotfiles/fish/profile ~/.profile # Ruby ln -s ~/.dotfiles/ruby/gemrc ~/.gemrc diff --git a/zsh/functions/extract b/zsh/functions/extract deleted file mode 100644 index 38af663..0000000 --- a/zsh/functions/extract +++ /dev/null @@ -1,28 +0,0 @@ -# credit: http://nparikh.org/notes/zshrc.txt -# Usage: smartextract -# Description: extracts archived files / mounts disk images -# Note: .dmg/hdiutil is Mac OS X-specific. - -extract () { - if [ -f $1 ]; then - case $1 in - *.tar.bz2) tar -jxvf $1 ;; - *.tar.gz) tar -zxvf $1 ;; - *.bz2) bunzip2 $1 ;; - *.dmg) hdiutil mount $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar -xvf $1 ;; - *.tbz2) tar -jxvf $1 ;; - *.tgz) tar -zxvf $1 ;; - *.zip) unzip $1 ;; - *.ZIP) unzip $1 ;; - *.pax) cat $1 | pax -r ;; - *.pax.Z) uncompress $1 --stdout | pax -r ;; - *.Z) uncompress $1 ;; - *) echo "'$1' cannot be extracted/mounted via smartextract()" ;; - esac - else - echo "'$1' is not a valid file" - fi -} - diff --git a/zsh/support/dock_delay.zsh b/zsh/support/dock_delay.zsh deleted file mode 100644 index d18e4f3..0000000 --- a/zsh/support/dock_delay.zsh +++ /dev/null @@ -1,3 +0,0 @@ -dock-delay() { - defaults write com.apple.Dock autohide-delay -float $1 && killall Dock -} diff --git a/zsh/support/show_colors.zsh b/zsh/support/show_colors.zsh deleted file mode 100644 index 2cab830..0000000 --- a/zsh/support/show_colors.zsh +++ /dev/null @@ -1,3 +0,0 @@ -show-colors() { - for code in {000..255}; do print -P -- "$code: %F{$code}Lorem ipsum dolor sit amet%f"; done -}