summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/functions.zsh24
-rw-r--r--lib/termsupport.zsh2
-rw-r--r--plugins/github/README.md46
-rw-r--r--plugins/github/_github40
-rw-r--r--plugins/github/github.plugin.zsh101
-rw-r--r--tools/uninstall.sh21
6 files changed, 109 insertions, 125 deletions
diff --git a/lib/functions.zsh b/lib/functions.zsh
index efb73a1bd..8ef3420bb 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -28,7 +28,10 @@ function open_command() {
;;
esac
- nohup $open_cmd "$@" &>/dev/null
+ # don't use nohup on OSX
+ [[ "$OSTYPE" != darwin* ]] && open_cmd="nohup $open_cmd"
+
+ $open_cmd "$@" &>/dev/null
}
#
@@ -67,7 +70,7 @@ function try_alias_value() {
#
# Arguments:
# 1. name - The variable to set
-# 2. val - The default value
+# 2. val - The default value
# Return value:
# 0 if the variable exists, 3 if it was set
#
@@ -81,12 +84,12 @@ function default() {
#
# Arguments:
# 1. name - The env variable to set
-# 2. val - The default value
+# 2. val - The default value
# Return value:
# 0 if the env variable exists, 3 if it was set
#
function env_default() {
- env | grep -q "^$1=" && return 0
+ env | grep -q "^$1=" && return 0
export "$1=$2" && return 3
}
@@ -101,7 +104,7 @@ zmodload zsh/langinfo
#
# By default, reserved characters and unreserved "mark" characters are
# not escaped by this function. This allows the common usage of passing
-# an entire URL in, and encoding just special characters in it, with
+# an entire URL in, and encoding just special characters in it, with
# the expectation that reserved and mark characters are used appropriately.
# The -r and -m options turn on escaping of the reserved and mark characters,
# respectively, which allows arbitrary strings to be fully escaped for
@@ -111,8 +114,8 @@ zmodload zsh/langinfo
# Returns nonzero if encoding failed.
#
# Usage:
-# omz_urlencode [-r] [-m] <string>
-#
+# omz_urlencode [-r] [-m] [-P] <string>
+#
# -r causes reserved characters (;/?:@&=+$,) to be escaped
#
# -m causes "mark" characters (_.!~*''()-) to be escaped
@@ -177,8 +180,8 @@ function omz_urlencode() {
# URL-decode a string
#
# Decodes a RFC 2396 URL-encoded (%-escaped) string.
-# This decodes the '+' and '%' escapes in the input string, and leaves
-# other characters unchanged. Does not enforce that the input is a
+# This decodes the '+' and '%' escapes in the input string, and leaves
+# other characters unchanged. Does not enforce that the input is a
# valid URL-encoded string. This is a convenience to allow callers to
# pass in a full URL or similar strings and decode them for human
# presentation.
@@ -196,7 +199,7 @@ function omz_urldecode {
local caller_encoding=$langinfo[CODESET]
local LC_ALL=C
export LC_ALL
-
+
# Change + back to ' '
local tmp=${encoded_url:gs/+/ /}
# Protect other escapes to pass through the printf unchanged
@@ -220,4 +223,3 @@ function omz_urldecode {
echo -E "$decoded"
}
-
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 5f61fe8ef..4c5068e9b 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -74,7 +74,7 @@ if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
# the host name to disambiguate local vs. remote paths.
# Percent-encode the pathname.
- local URL_PATH=$(omz_urlencode -P $PWD)
+ local URL_PATH="$(omz_urlencode -P $PWD)"
[[ $? != 0 ]] && return 1
local PWD_URL="file://$HOST$URL_PATH"
# Undocumented Terminal.app-specific control sequence
diff --git a/plugins/github/README.md b/plugins/github/README.md
new file mode 100644
index 000000000..21b7367f7
--- /dev/null
+++ b/plugins/github/README.md
@@ -0,0 +1,46 @@
+# github
+
+This plugin supports working with GitHub the command line. It provides a few things:
+
+* Sets up the `hub` wrapper and completions for the `git` command if you have `hub` installed.
+* Completion for the `github` Ruby gem.
+* Convenience functions for working with repos and URLs.
+
+### Functions
+
+* `empty_gh` - Creates a new empty repo (with a `README.md`) and pushes it to GitHub
+* `new_gh` - Initializes an existing directory as a repo and pushes it to GitHub
+* `exist_gh` - Takes an existing repo and pushes it to GitHub
+* `git.io` - Shortens a URL using [git.io](http://git.io)
+
+
+## Installation
+
+[Hub](http://github.com/github/hub) needs to be installed if you want to use it. On OS X with Homebrew, this can be done with `brew install hub`. The `hub` completion definition needs to be added to your `$FPATH` before initializing OMZ.
+
+The [`github` Ruby gem](http://github.com/defunkt/github-gem) needs to be installed if you want to use it.
+
+### Configuration
+
+These settings affect `github`'s behavior.
+
+#### Environment variables
+
+* `$GITHUB_USER`
+* `$GITHUB_PASSWORD`
+
+#### Git configuration options
+
+* `github.user` - GitHub username for repo operations
+
+See `man hub` for more details.
+
+### Homebrew installation note
+
+If you have installed `hub` using Homebrew, its completions may not be on your `$FPATH` if you are using the system `zsh`. Homebrew installs `zsh` completion definitions to `/usr/local/share/zsh/site-functions`, which on `$FPATH` for the Homebrew-installed `zsh`, but not for the system `zsh`. If you want it to work with the system `zsh`, add this to your `~/.zshrc` before it sources `oh-my-zsh.sh`.
+
+```zsh
+if (( ! ${fpath[(I)/usr/local/share/zsh/site-functions]} )); then
+ FPATH=/usr/local/share/zsh/site-functions:$FPATH
+fi
+```
diff --git a/plugins/github/_github b/plugins/github/_github
deleted file mode 100644
index 83e1713c7..000000000
--- a/plugins/github/_github
+++ /dev/null
@@ -1,40 +0,0 @@
-#compdef github
-#autoload
-
-# in order to make this work, you will need to have the github gem installed
-# http://github.com/defunkt/github-gem
-
-# github zsh completion, based on homebrew completion
-
-local -a _1st_arguments
-_1st_arguments=(
- 'browse:Open this repo in a web browser'
- 'clone:Clone a repo'
- 'config:Automatically set configuration info, or pass args to specify'
- 'create-from-local:Create a new GitHub repository from the current local repository'
- 'create:Create a new empty GitHub repository'
- 'fetch:Fetch from a remote to a local branch'
- 'fetch_all:Fetch all refs from a user'
- 'fork:Forks a GitHub repository'
- 'home:Open this repos master branch in a web browser'
- 'ignore:Ignore a SHA from github network commits'
- 'info:Info about this project'
- 'issues:Project issues tools'
- 'network:Project network tools - sub-commands : web [user], list, fetch, commits'
- 'open:Open the given user/project in a web browser'
- 'pull-request:Generate the text for a pull request'
- 'pull:Pull from a remote'
- 'search:Search GitHub for the given repository name'
- 'track:Track another users repository'
-)
-
-local expl
-local -a pkgs installed_pkgs
-
-_arguments \
- '*:: :->subcmds' && return 0
-
-if (( CURRENT == 1 )); then
- _describe -t commands "github subcommand" _1st_arguments
- return
-fi
diff --git a/plugins/github/github.plugin.zsh b/plugins/github/github.plugin.zsh
index bd69b1bd5..ca19901fd 100644
--- a/plugins/github/github.plugin.zsh
+++ b/plugins/github/github.plugin.zsh
@@ -1,56 +1,25 @@
-# Setup hub function for git, if it is available; http://github.com/defunkt/hub
-if [ "$commands[(I)hub]" ] && [ "$commands[(I)ruby]" ]; then
- # Autoload _git completion functions
- if declare -f _git > /dev/null; then
- _git
- fi
-
- if declare -f _git_commands > /dev/null; then
- _hub_commands=(
- 'alias:show shell instructions for wrapping git'
- 'pull-request:open a pull request on GitHub'
- 'fork:fork origin repo on GitHub'
- 'create:create new repo on GitHub for the current project'
- 'browse:browse the project on GitHub'
- 'compare:open GitHub compare view'
- )
- # Extend the '_git_commands' function with hub commands
- eval "$(declare -f _git_commands | sed -e 's/base_commands=(/base_commands=(${_hub_commands} /')"
- fi
- # eval `hub alias -s zsh`
- function git(){
- if ! (( $+_has_working_hub )); then
- hub --version &> /dev/null
- _has_working_hub=$(($? == 0))
- fi
- if (( $_has_working_hub )) ; then
- hub "$@"
- else
- command git "$@"
- fi
- }
+# Set up hub wrapper for git, if it is available; http://github.com/github/hub
+if [ "$commands[(I)hub]" ]; then
+ if hub --version &>/dev/null; then
+ eval $(hub alias -s zsh)
+ fi
fi
# Functions #################################################################
-# https://github.com/dbb
+# Based on https://github.com/dbb/githome/blob/master/.config/zsh/functions
-
-# empty_gh [NAME_OF_REPO]
+# empty_gh <NAME_OF_REPO>
#
# Use this when creating a new repo from scratch.
+# Creates a new repo with a blank README.md in it and pushes it up to GitHub.
empty_gh() { # [NAME_OF_REPO]
- repo=$1
- ghuser=$( git config github.user )
+ emulate -L zsh
+ local repo=$1
- mkdir "$repo"
- cd "$repo"
- git init
- touch README
- git add README
- git commit -m 'Initial commit.'
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ mkdir "$repo"
+ touch "$repo/README.md"
+ new_gh "$repo"
}
# new_gh [DIRECTORY]
@@ -58,16 +27,25 @@ empty_gh() { # [NAME_OF_REPO]
# Use this when you have a directory that is not yet set up for git.
# This function will add all non-hidden files to git.
new_gh() { # [DIRECTORY]
- cd "$1"
- ghuser=$( git config github.user )
+ emulate -L zsh
+ local repo="$1"
+ cd "$repo" \
+ || return
- git init
- # add all non-dot files
- print '.*'"\n"'*~' >> .gitignore
- git add ^.*
- git commit -m 'Initial commit.'
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ git init \
+ || return
+ # add all non-dot files
+ print '.*'"\n"'*~' >> .gitignore
+ git add [^.]* \
+ || return
+ git add .gitignore \
+ || return
+ git commit -m 'Initial commit.' \
+ || return
+ hub create \
+ || return
+ git push -u origin master \
+ || return
}
# exist_gh [DIRECTORY]
@@ -75,13 +53,13 @@ new_gh() { # [DIRECTORY]
# Use this when you have a git repo that's ready to go and you want to add it
# to your GitHub.
exist_gh() { # [DIRECTORY]
- cd "$1"
- name=$( git config user.name )
- ghuser=$( git config github.user )
- repo=$1
+ emulate -L zsh
+ local repo=$1
+ cd "$repo"
- git remote add origin git@github.com:${ghuser}/${repo}.git
- git push -u origin master
+ hub create \
+ || return
+ git push -u origin master
}
# git.io "GitHub URL"
@@ -91,7 +69,10 @@ exist_gh() { # [DIRECTORY]
# source: https://github.com/nvogel/dotzsh
# documentation: https://github.com/blog/985-git-io-github-url-shortener
#
-git.io() {curl -i -s http://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "}
+git.io() {
+ emulate -L zsh
+ curl -i -s http://git.io -F "url=$1" | grep "Location" | cut -f 2 -d " "
+}
# End Functions #############################################################
diff --git a/tools/uninstall.sh b/tools/uninstall.sh
index 9ad1b64a6..bf2244be8 100644
--- a/tools/uninstall.sh
+++ b/tools/uninstall.sh
@@ -1,34 +1,29 @@
read -r -p "Are you sure you want to remove Oh My Zsh? [y/N] " confirmation
-if [ "$confirmation" != y ] && [ "$confirmation" != Y ]
-then
+if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then
echo "Uninstall cancelled"
exit
fi
echo "Removing ~/.oh-my-zsh"
-if [ -d ~/.oh-my-zsh ]
-then
+if [ -d ~/.oh-my-zsh ]; then
rm -rf ~/.oh-my-zsh
fi
echo "Looking for original zsh config..."
-if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]
-then
+if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]; then
echo "Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc";
- if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]
- then
- ZSHRC_SAVE=".zshrc.omz-uninstalled-`date +%Y%m%d%H%M%S`";
+ if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
+ ZSHRC_SAVE=".zshrc.omz-uninstalled-$(date +%Y%m%d%H%M%S)";
echo "Found ~/.zshrc -- Renaming to ~/${ZSHRC_SAVE}";
- mv ~/.zshrc ~/${ZSHRC_SAVE};
+ mv ~/.zshrc ~/"${ZSHRC_SAVE}";
fi
mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc;
- source ~/.zshrc;
+ echo "Your original zsh config was restored. Please restart your session."
else
- if hash chsh >/dev/null 2>&1
- then
+ if hash chsh >/dev/null 2>&1; then
echo "Switching back to bash"
chsh -s /bin/bash
else