Commit ab0f2f9d577352a488e68c3a0f9cf810b2afd034

Authored by mj
1 parent 238d8e65a1
Exists in master and in 2 other branches 02-merge, dev

Squashed 'repos/robbyrussell/oh-my-zsh/' changes from 599831b..3ea3384

3ea3384 Merge pull request #4041 from apjanke/fix-jira-prefix-comment-merge
c968346 Merge pull request #4106 from apjanke/venvw-no-realpath
c1f1f91 virtualenvwrapper: Replace "realpath" with portable zsh-native `:A` and `:h` modifiers
d0670aa Fix merge conflict for jira-prefix and jira add comment

git-subtree-dir: repos/robbyrussell/oh-my-zsh
git-subtree-split: 3ea33841863c4f5f22a27e64ae7950d901b674af

Showing 2 changed files with 7 additions and 13 deletions Inline Diff

plugins/jira/jira.plugin.zsh
1 # To use: add a .jira-url file in the base of your project 1 # To use: add a .jira-url file in the base of your project
2 # You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory 2 # You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory
3 # .jira-url in the current directory takes precedence 3 # .jira-url in the current directory takes precedence
4 # 4 #
5 # If you use Rapid Board, set: 5 # If you use Rapid Board, set:
6 #JIRA_RAPID_BOARD="true" 6 #JIRA_RAPID_BOARD="true"
7 # in you .zshrc 7 # in you .zshrc
8 # 8 #
9 # Setup: cd to/my/project 9 # Setup: cd to/my/project
10 # echo "https://name.jira.com" >> .jira-url 10 # echo "https://name.jira.com" >> .jira-url
11 # Usage: jira # opens a new issue 11 # Usage: jira # opens a new issue
12 # jira ABC-123 # Opens an existing issue 12 # jira ABC-123 # Opens an existing issue
13 open_jira_issue () { 13 open_jira_issue () {
14 local open_cmd 14 local open_cmd
15 if [[ "$OSTYPE" = darwin* ]]; then 15 if [[ "$OSTYPE" = darwin* ]]; then
16 open_cmd='open' 16 open_cmd='open'
17 else 17 else
18 open_cmd='xdg-open' 18 open_cmd='xdg-open'
19 fi 19 fi
20 20
21 if [ -f .jira-url ]; then 21 if [ -f .jira-url ]; then
22 jira_url=$(cat .jira-url) 22 jira_url=$(cat .jira-url)
23 elif [ -f ~/.jira-url ]; then 23 elif [ -f ~/.jira-url ]; then
24 jira_url=$(cat ~/.jira-url) 24 jira_url=$(cat ~/.jira-url)
25 elif [[ "x$JIRA_URL" != "x" ]]; then 25 elif [[ "x$JIRA_URL" != "x" ]]; then
26 jira_url=$JIRA_URL 26 jira_url=$JIRA_URL
27 else 27 else
28 echo "JIRA url is not specified anywhere." 28 echo "JIRA url is not specified anywhere."
29 return 1 29 return 1
30 fi 30 fi
31 31
32 if [ -f .jira-prefix ]; then 32 if [ -f .jira-prefix ]; then
33 jira_prefix=$(cat .jira-prefix) 33 jira_prefix=$(cat .jira-prefix)
34 elif [ -f ~/.jira-prefix ]; then 34 elif [ -f ~/.jira-prefix ]; then
35 jira_prefix=$(cat ~/.jira-prefix) 35 jira_prefix=$(cat ~/.jira-prefix)
36 else 36 else
37 jira_prefix="" 37 jira_prefix=""
38 fi 38 fi
39 39
40 if [ -z "$1" ]; then 40 if [ -z "$1" ]; then
41 echo "Opening new issue" 41 echo "Opening new issue"
42 $open_cmd "${jira_url}/secure/CreateIssue!default.jspa" 42 $open_cmd "${jira_url}/secure/CreateIssue!default.jspa"
43 elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then 43 elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
44 jira_query $@ 44 jira_query $@
45 else
46 echo "Opening issue #$1"
47 if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
48 $open_cmd "$jira_url/issues/$jira_prefix$1"
49 else
50 $open_cmd "$jira_url/browse/$jira_prefix$1"
51 fi
52 else 45 else
53 local addcomment='' 46 local addcomment=''
54 if [[ "$2" == "m" ]]; then 47 if [[ "$2" == "m" ]]; then
55 addcomment="#add-comment" 48 addcomment="#add-comment"
56 echo "Add comment to issue #$1" 49 echo "Add comment to issue #$1"
57 else 50 else
58 echo "Opening issue #$1" 51 echo "Opening issue #$1"
59 fi 52 fi
60 53
61 if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then 54 if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
62 $open_cmd "$jira_url/issues/$1$addcomment" 55 $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment"
63 else 56 else
64 $open_cmd "$jira_url/browse/$1$addcomment" 57 $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment"
65 fi 58 fi
66 fi 59 fi
67 } 60 }
68 61
69 jira_name () { 62 jira_name () {
70 if [[ -z "$1" ]]; then 63 if [[ -z "$1" ]]; then
71 if [[ "x${JIRA_NAME}" != "x" ]]; then 64 if [[ "x${JIRA_NAME}" != "x" ]]; then
72 jira_name=${JIRA_NAME} 65 jira_name=${JIRA_NAME}
73 else 66 else
74 echo "JIRA_NAME not specified" 67 echo "JIRA_NAME not specified"
75 return 1 68 return 1
76 fi 69 fi
77 else 70 else
78 jira_name=$@ 71 jira_name=$@
79 fi 72 fi
80 } 73 }
81 74
82 jira_query () { 75 jira_query () {
83 verb="$1" 76 verb="$1"
84 if [[ "${verb}" = "reported" ]]; then 77 if [[ "${verb}" = "reported" ]]; then
85 lookup=reporter 78 lookup=reporter
86 preposition=by 79 preposition=by
87 elif [[ "${verb}" = "assigned" ]]; then 80 elif [[ "${verb}" = "assigned" ]]; then
88 lookup=assignee 81 lookup=assignee
89 preposition=to 82 preposition=to
90 else 83 else
91 echo "not a valid lookup $verb" 84 echo "not a valid lookup $verb"
92 return 1 85 return 1
93 fi 86 fi
94 shift 1 87 shift 1
95 jira_name $@ 88 jira_name $@
96 if [[ $? = 1 ]]; then 89 if [[ $? = 1 ]]; then
97 return 1 90 return 1
98 fi 91 fi
99 echo "Browsing issues ${verb} ${preposition} ${jira_name}" 92 echo "Browsing issues ${verb} ${preposition} ${jira_name}"
100 $open_cmd "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC" 93 $open_cmd "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC"
101 } 94 }
102 95
103 alias jira='open_jira_issue' 96 alias jira='open_jira_issue'
104 97
105 98
plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
1 virtualenvwrapper='virtualenvwrapper.sh' 1 virtualenvwrapper='virtualenvwrapper.sh'
2 2
3 if (( $+commands[$virtualenvwrapper] )); then 3 if (( $+commands[$virtualenvwrapper] )); then
4 function { 4 function {
5 setopt local_options 5 setopt local_options
6 unsetopt equals 6 unsetopt equals
7 source ${${virtualenvwrapper}:c} 7 source ${${virtualenvwrapper}:c}
8 } 8 }
9 elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then 9 elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then
10 function { 10 function {
11 setopt local_options 11 setopt local_options
12 unsetopt equals 12 unsetopt equals
13 virtualenvwrapper="/etc/bash_completion.d/virtualenvwrapper" 13 virtualenvwrapper="/etc/bash_completion.d/virtualenvwrapper"
14 source "/etc/bash_completion.d/virtualenvwrapper" 14 source "/etc/bash_completion.d/virtualenvwrapper"
15 } 15 }
16 else 16 else
17 print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}.\n"\ 17 print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}.\n"\
18 "Please install with \`pip install virtualenvwrapper\`" >&2 18 "Please install with \`pip install virtualenvwrapper\`" >&2
19 return 19 return
20 fi 20 fi
21 if ! type workon &>/dev/null; then 21 if ! type workon &>/dev/null; then
22 print "zsh virtualenvwrapper plugin: shell function 'workon' not defined.\n"\ 22 print "zsh virtualenvwrapper plugin: shell function 'workon' not defined.\n"\
23 "Please check ${virtualenvwrapper}" >&2 23 "Please check ${virtualenvwrapper}" >&2
24 return 24 return
25 fi 25 fi
26 26
27 if [[ "$WORKON_HOME" == "" ]]; then 27 if [[ "$WORKON_HOME" == "" ]]; then
28 print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2 28 print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2
29 return 29 return
30 fi 30 fi
31 31
32 if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then 32 if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
33 # Automatically activate Git projects's virtual environments based on the 33 # Automatically activate Git projects' virtual environments based on the
34 # directory name of the project. Virtual environment name can be overridden 34 # directory name of the project. Virtual environment name can be overridden
35 # by placing a .venv file in the project root with a virtualenv name in it 35 # by placing a .venv file in the project root with a virtualenv name in it
36 function workon_cwd { 36 function workon_cwd {
37 if [ ! $WORKON_CWD ]; then 37 if [ ! $WORKON_CWD ]; then
38 WORKON_CWD=1 38 WORKON_CWD=1
39 # Check if this is a Git repo 39 # Check if this is a Git repo
40 PROJECT_ROOT=`pwd` 40 # Get absolute path, resolving symlinks
41 PROJECT_ROOT="${PWD:A}"
41 while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" ]]; do 42 while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" ]]; do
42 PROJECT_ROOT=`realpath $PROJECT_ROOT/..` 43 PROJECT_ROOT="${PROJECT_ROOT:h}"
43 done 44 done
44 if [[ "$PROJECT_ROOT" == "/" ]]; then 45 if [[ "$PROJECT_ROOT" == "/" ]]; then
45 PROJECT_ROOT="." 46 PROJECT_ROOT="."
46 fi 47 fi
47 # Check for virtualenv name override 48 # Check for virtualenv name override
48 if [[ -f "$PROJECT_ROOT/.venv" ]]; then 49 if [[ -f "$PROJECT_ROOT/.venv" ]]; then
49 ENV_NAME=`cat "$PROJECT_ROOT/.venv"` 50 ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
50 elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then 51 elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
51 ENV_NAME="$PROJECT_ROOT/.venv" 52 ENV_NAME="$PROJECT_ROOT/.venv"
52 elif [[ "$PROJECT_ROOT" != "." ]]; then 53 elif [[ "$PROJECT_ROOT" != "." ]]; then
53 ENV_NAME=`basename "$PROJECT_ROOT"` 54 ENV_NAME="${PROJECT_ROOT:t}"
54 else 55 else
55 ENV_NAME="" 56 ENV_NAME=""
56 fi 57 fi
57 if [[ "$ENV_NAME" != "" ]]; then 58 if [[ "$ENV_NAME" != "" ]]; then
58 # Activate the environment only if it is not already active 59 # Activate the environment only if it is not already active
59 if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then 60 if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
60 if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then 61 if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
61 workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" 62 workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
62 elif [[ -e "$ENV_NAME/bin/activate" ]]; then 63 elif [[ -e "$ENV_NAME/bin/activate" ]]; then
63 source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" 64 source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
64 fi 65 fi
65 fi 66 fi
66 elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then 67 elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
67 # We've just left the repo, deactivate the environment 68 # We've just left the repo, deactivate the environment
68 # Note: this only happens if the virtualenv was activated automatically 69 # Note: this only happens if the virtualenv was activated automatically
69 deactivate && unset CD_VIRTUAL_ENV 70 deactivate && unset CD_VIRTUAL_ENV
70 fi 71 fi
71 unset PROJECT_ROOT 72 unset PROJECT_ROOT
72 unset WORKON_CWD 73 unset WORKON_CWD
73 fi 74 fi
74 } 75 }
75 76
76 # Append workon_cwd to the chpwd_functions array, so it will be called on cd 77 # Append workon_cwd to the chpwd_functions array, so it will be called on cd
77 # http://zsh.sourceforge.net/Doc/Release/Functions.html 78 # http://zsh.sourceforge.net/Doc/Release/Functions.html
78 if ! (( $chpwd_functions[(I)workon_cwd] )); then 79 if ! (( $chpwd_functions[(I)workon_cwd] )); then
79 chpwd_functions+=(workon_cwd) 80 chpwd_functions+=(workon_cwd)
80 fi 81 fi
81 fi 82 fi
82 83