Unverified Commit 18ee5dff authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

Merge branch 'master' into clipboard

parents d81cd753 368198b7
......@@ -33,6 +33,7 @@ alias zunner='zeus runner'
# Cucumber
alias zcu='zeus cucumber'
alias zucumber='zeus cucumber'
alias zwip='zeus cucumber --profile wip'
# Rspec
alias zspec='zeus rspec'
......
# zsh-interactive-cd
This plugin adds a fish-like interactive tab completion for the `cd` command.
To use it, add `zsh-interactive-cd` to the plugins array of your zshrc file:
```zsh
plugins=(... zsh-interactive-cd)
```
![demo](https://user-images.githubusercontent.com/1441704/74360670-cb202900-4dc5-11ea-9734-f60caf726e85.gif)
## Usage
Press tab for completion as usual, it'll launch fzf automatically. Check fzf’s [readme](https://github.com/junegunn/fzf#search-syntax) for more search syntax usage.
## Requirements
This plugin requires [fzf](https://github.com/junegunn/fzf). Install it by following
its [installation instructions](https://github.com/junegunn/fzf#installation).
## Author
[Henry Chang](https://github.com/changyuheng)
# Copyright (c) 2017 Henry Chang
__zic_fzf_prog() {
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] \
&& echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
}
__zic_matched_subdir_list() {
local dir length seg starts_with_dir
if [[ "$1" == */ ]]; then
dir="$1"
if [[ "$dir" != / ]]; then
dir="${dir: : -1}"
fi
length=$(echo -n "$dir" | wc -c)
if [ "$dir" = "/" ]; then
length=0
fi
find -L "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null \
| cut -b $(( ${length} + 2 ))- | sed '/^$/d' | while read -r line; do
if [[ "${line[1]}" == "." ]]; then
continue
fi
echo "$line"
done
else
dir=$(dirname -- "$1")
length=$(echo -n "$dir" | wc -c)
if [ "$dir" = "/" ]; then
length=0
fi
seg=$(basename -- "$1")
starts_with_dir=$( \
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
| while read -r line; do
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
continue
fi
if [[ "$line" == "$seg"* ]]; then
echo "$line"
fi
done
)
if [ -n "$starts_with_dir" ]; then
echo "$starts_with_dir"
else
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
| while read -r line; do
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
continue
fi
if [[ "$line" == *"$seg"* ]]; then
echo "$line"
fi
done
fi
fi
}
_zic_list_generator() {
__zic_matched_subdir_list "${(Q)@[-1]}" | sort
}
_zic_complete() {
setopt localoptions nonomatch
local l matches fzf tokens base
l=$(_zic_list_generator $@)
if [ -z "$l" ]; then
zle ${__zic_default_completion:-expand-or-complete}
return
fi
fzf=$(__zic_fzf_prog)
if [ $(echo $l | wc -l) -eq 1 ]; then
matches=${(q)l}
else
matches=$(echo $l \
| FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} \
--reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS \
--bind 'shift-tab:up,tab:down'" ${=fzf} \
| while read -r item; do
echo -n "${(q)item} "
done)
fi
matches=${matches% }
if [ -n "$matches" ]; then
tokens=(${(z)LBUFFER})
base="${(Q)@[-1]}"
if [[ "$base" != */ ]]; then
if [[ "$base" == */* ]]; then
base="$(dirname -- "$base")"
if [[ ${base[-1]} != / ]]; then
base="$base/"
fi
else
base=""
fi
fi
LBUFFER="${tokens[1]} "
if [ -n "$base" ]; then
base="${(q)base}"
if [ "${tokens[2][1]}" = "~" ]; then
base="${base/#$HOME/~}"
fi
LBUFFER="${LBUFFER}${base}"
fi
LBUFFER="${LBUFFER}${matches}/"
fi
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
}
zic-completion() {
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
local tokens cmd
tokens=(${(z)LBUFFER})
cmd=${tokens[1]}
if [[ "$LBUFFER" =~ "^\ *cd$" ]]; then
zle ${__zic_default_completion:-expand-or-complete}
elif [ "$cmd" = cd ]; then
_zic_complete ${tokens[2,${#tokens}]/#\~/$HOME}
else
zle ${__zic_default_completion:-expand-or-complete}
fi
}
[ -z "$__zic_default_completion" ] && {
binding=$(bindkey '^I')
# $binding[(s: :w)2]
# The command substitution and following word splitting to determine the
# default zle widget for ^I formerly only works if the IFS parameter contains
# a space via $binding[(w)2]. Now it specifically splits at spaces, regardless
# of IFS.
[[ $binding =~ 'undefined-key' ]] || __zic_default_completion=$binding[(s: :w)2]
unset binding
}
zle -N zic-completion
bindkey -M emacs '^I' zic-completion
bindkey -M viins '^I' zic-completion
......@@ -7,7 +7,7 @@ export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
......
......@@ -2,32 +2,41 @@
# Repo: https://github.com/andyfleming/oh-my-zsh
# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
# primary prompt
PROMPT='$FG[237]------------------------------------------------------------%{$reset_color%}
$FG[032]%~\
$(git_prompt_info) \
$FG[105]%(!.#.»)%{$reset_color%} '
PROMPT2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='${return_code}'
# settings
typeset +H return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
typeset +H my_gray="$FG[237]"
typeset +H my_orange="$FG[214]"
# separator dashes size
function afmagic_dashes {
[[ -n "${VIRTUAL_ENV-}" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" && "$PS1" = \(* ]] \
&& echo $(( COLUMNS - ${#VIRTUAL_ENV} - 3 )) \
|| echo $COLUMNS
}
# color vars
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'
# primary prompt
PS1='$FG[237]${(l.$(afmagic_dashes)..-.)}%{$reset_color%}
$FG[032]%~$(git_prompt_info)$(hg_prompt_info) $FG[105]%(!.#.»)%{$reset_color%} '
PS2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='${return_code}'
# right prompt
if type "virtualenv_prompt_info" > /dev/null
then
RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%'
else
RPROMPT='$my_gray%n@%m%{$reset_color%}%'
fi
(( $+functions[virtualenv_prompt_info] )) && RPS1+='$(virtualenv_prompt_info)'
RPS1+=' $my_gray%n@%m%{$reset_color%}%'
# git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
# hg settings
ZSH_THEME_HG_PROMPT_PREFIX="$FG[075]($FG[078]"
ZSH_THEME_HG_PROMPT_CLEAN=""
ZSH_THEME_HG_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_HG_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
# virtualenv settings
ZSH_THEME_VIRTUALENV_PREFIX=" $FG[075]["
ZSH_THEME_VIRTUALENV_SUFFIX="]%{$reset_color%}"
......@@ -141,20 +141,26 @@ prompt_git() {
prompt_bzr() {
(( $+commands[bzr] )) || return
if (bzr status >/dev/null 2>&1); then
status_mod=`bzr status | head -n1 | grep "modified" | wc -m`
status_all=`bzr status | head -n1 | wc -m`
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
# Test if bzr repository in directory hierarchy
local dir="$PWD"
while [[ ! -d "$dir/.bzr" ]]; do
[[ "$dir" = "/" ]] && return
dir="${dir:h}"
done
local bzr_status status_mod status_all revision
if bzr_status=$(bzr status 2>&1); then
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
revision=$(bzr log -r-1 --log-format line | cut -d: -f1)
if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black
echo -n "bzr@"$revision "✚ "
prompt_segment yellow black "bzr@$revision ✚"
else
if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black
echo -n "bzr@"$revision
prompt_segment yellow black "bzr@$revision"
else
prompt_segment green black
echo -n "bzr@"$revision
prompt_segment green black "bzr@$revision"
fi
fi
fi
......
# AVIT ZSH Theme
PROMPT='
$(_user_host)${_current_dir} $(git_prompt_info) $(_ruby_version)
%{$fg[$CARETCOLOR]%}▶%{$resetcolor%} '
# settings
typeset +H _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
typeset +H _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
typeset +H _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
PROMPT2='%{$fg[$CARETCOLOR]%}◀%{$reset_color%} '
PROMPT='
$(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info)
%{%(!.%F{red}.%F{white})%}▶%{$resetcolor%} '
RPROMPT='$(_vi_status)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
PROMPT2='%{%(!.%F{red}.%F{white})%}◀%{$reset_color%} '
local _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
local _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
local _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
function _current_dir() {
local _max_pwd_length="65"
if [[ $(echo -n $PWD | wc -c) -gt ${_max_pwd_length} ]]; then
echo "%{$fg_bold[blue]%}%-2~ ... %3~%{$reset_color%} "
else
echo "%{$fg_bold[blue]%}%~%{$reset_color%} "
fi
}
RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
function _user_host() {
local me
if [[ -n $SSH_CONNECTION ]]; then
me="%n@%m"
elif [[ $LOGNAME != $USER ]]; then
......@@ -32,61 +25,41 @@ function _user_host() {
fi
}
function _vi_status() {
if {echo $fpath | grep -q "plugins/vi-mode"}; then
echo "$(vi_mode_prompt_info)"
fi
}
function _ruby_version() {
if {echo $fpath | grep -q "plugins/rvm"}; then
echo "%{$fg[grey]%}$(rvm_prompt_info)%{$reset_color%}"
elif {echo $fpath | grep -q "plugins/rbenv"}; then
echo "%{$fg[grey]%}$(rbenv_prompt_info)%{$reset_color%}"
fi
}
# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
function _git_time_since_commit() {
# Only proceed if there is actually a commit.
local last_commit now seconds_since_last_commit
local minutes hours days years commit_age
# Only proceed if there is actually a commit.
if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
now=$(date +%s)
seconds_since_last_commit=$((now-last_commit))
# Totals
minutes=$((seconds_since_last_commit / 60))
hours=$((seconds_since_last_commit/3600))
# Sub-hours and sub-minutes
days=$((seconds_since_last_commit / 86400))
sub_hours=$((hours % 24))
sub_minutes=$((minutes % 60))
if [ $hours -ge 24 ]; then
commit_age="${days}d"
elif [ $minutes -gt 60 ]; then
commit_age="${sub_hours}h${sub_minutes}m"
hours=$((minutes / 60))
days=$((hours / 24))
years=$((days / 365))
if [[ $years -gt 0 ]]; then
commit_age="${years}y$((days % 365 ))d"
elif [[ $days -gt 0 ]]; then
commit_age="${days}d$((hours % 24))h"
elif [[ $hours -gt 0 ]]; then
commit_age+="${hours}h$(( minutes % 60 ))m"
else
commit_age="${minutes}m"
fi
color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL
echo "$color$commit_age%{$reset_color%}"
echo "${ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}${commit_age}%{$reset_color%}"
fi
}
if [[ $USER == "root" ]]; then
CARETCOLOR="red"
else
CARETCOLOR="white"
fi
MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}"
# Git prompt settings
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚ "
......@@ -96,6 +69,10 @@ ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}▴ "
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ "
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}◒ "
# Ruby prompt settings
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[grey]%}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}"
# Colors vary depending on time lapsed.
ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
......
......@@ -16,7 +16,7 @@ local venv_prompt='$(virtualenv_prompt_info)'
ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
PROMPT="╭─${venv_prompt}${user_host}${current_dir}${rvm_ruby}${git_branch}
PROMPT="╭─${user_host}${current_dir}${rvm_ruby}${git_branch}${venv_prompt}
╰─%B${user_symbol}%b "
RPROMPT="%B${return_code}%b"
......
# neuralsanwich.zsh-theme
if [ "x$OH_MY_ZSH_HG" = "x" ]; then
OH_MY_ZSH_HG="hg"
fi
function hg_prompt_info {
$OH_MY_ZSH_HG prompt --angle-brackets "\
if ! hg prompt 2>/dev/null; then
function hg_prompt_info { }
else
function hg_prompt_info {
hg prompt --angle-brackets "\
< on %{$fg[magenta]%}<branch>%{$reset_color%}>\
< at %{$fg[yellow]%}<tags|%{$reset_color%}, %{$fg[yellow]%}>%{$reset_color%}>\
%{$fg[green]%}<status|modified|unknown><update>%{$reset_color%}<
patches: <patches|join( → )|pre_applied(%{$fg[yellow]%})|post_applied(%{$reset_color%})|pre_unapplied(%{$fg_bold[black]%})|post_unapplied(%{$reset_color%})>>" 2>/dev/null
}
}
fi
function box_name {
[ -f ~/.box-name ] && cat ~/.box-name || echo ${SHORT_HOST:-$HOST}
......@@ -26,5 +24,9 @@ ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[red]%}?"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[orange]%}!"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
local return_status="%{$fg[red]%}%(?..✘)%{$reset_color%}"
RPROMPT='${return_status}$(battery_time_remaining) $(battery_pct_prompt)%{$reset_color%}'
RPROMPT='%{$fg[red]%}%(?..✘)%{$reset_color%}'
# Add battery status if the battery plugin is enabled
if (( $+functions[battery_pct_prompt] )); then
RPROMPT+='$(battery_time_remaining) $(battery_pct_prompt)%{$reset_color%}'
fi
# Evan describes this sexy prompt as: "a skinny, topless prompt"
# Evan's minimal prompt
PROMPT='%m :: %2~ %B»%b '
# ZSH Theme - Preview: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes#gallifrey
# ZSH Theme - Preview: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#gallifrey
return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
host_color="%(!.%{$fg[red]%}.%{$fg[green]%})"
......
#
# Kiwi ZSH Theme
#
(( $+functions[battery_pct_prompt] )) || function battery_pct_prompt { }
PROMPT='%{$fg_bold[green]%}┌[%{$fg_bold[cyan]%}kiwish-4.2%{$fg_bold[green]%}]-(%{$fg_bold[white]%}%2~%{$fg_bold[green]%})-$(git_prompt_info)$(svn_prompt_info)$(battery_pct_prompt)
└> % %{$reset_color%}'
......
PROMPT='%{$fg[yellow]%}λ %m %{$fg[green]%}%c %{$fg[yellow]%}→ $(git_prompt_info)%{$reset_color%}'
PROMPT='%{$fg[yellow]%}λ %m %{$fg[green]%}%c %{$fg[yellow]%}→ $(git_prompt_info)$(hg_prompt_info)%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="λ %{$fg[blue]%}git %{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[yellow]%} → %{$reset_color%}"
ZSH_THEME_HG_PROMPT_PREFIX="λ %{$fg[blue]%}hg %{$fg[red]%}"
ZSH_THEME_HG_PROMPT_SUFFIX="%{$fg[yellow]%} → %{$reset_color%}"
......@@ -28,7 +28,8 @@ prompt_setup_pygmalion(){
base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
precmd_functions+=(prompt_pygmalion_precmd)
autoload -U add-zsh-hook
add-zsh-hook precmd prompt_pygmalion_precmd
}
prompt_pygmalion_precmd(){
......@@ -46,5 +47,3 @@ prompt_pygmalion_precmd(){
}
prompt_setup_pygmalion
......@@ -12,7 +12,8 @@ prompt_setup_pygmalion(){
base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
precmd_functions+=(prompt_pygmalion_precmd)
autoload -U add-zsh-hook
add-zsh-hook precmd prompt_pygmalion_precmd
}
prompt_pygmalion_precmd(){
......@@ -30,5 +31,3 @@ prompt_pygmalion_precmd(){
}
prompt_setup_pygmalion
# Make themes a unique array
typeset -Ua themes
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = array && ${#ZSH_THEME_RANDOM_CANDIDATES[@]} -gt 0 ]]; then
# Use ZSH_THEME_RANDOM_CANDIDATES if properly defined
themes=($ZSH_THEME_RANDOM_CANDIDATES)
else
# Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
themes=(
"$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
"$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
"$ZSH"/themes/*.zsh-theme(N:t:r)
)
# Remove blacklisted themes from the list
for theme in ${ZSH_THEME_RANDOM_BLACKLIST[@]}; do
themes=("${(@)themes:#$theme}")
done
fi
# Choose a theme out of the pool of candidates
N=${#themes[@]}
(( N = (RANDOM%N) + 1 ))
RANDOM_THEME="${themes[$N]}"
unset N themes theme
# Source theme
if [[ -f "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme"
elif [[ -f "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme"
elif [[ -f "$ZSH/themes/$RANDOM_THEME.zsh-theme" ]]; then
source "$ZSH/themes/$RANDOM_THEME.zsh-theme"
else
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' not found"
return 1
fi
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
......
# Sunrise theme for oh-my-zsh
# Intended to be used with Solarized: http://ethanschoonover.com/solarized
# Intended to be used with Solarized: https://ethanschoonover.com/solarized
# Color shortcuts
R=$fg_no_bold[red]
......
#!/bin/sh
#
# This script should be run via curl:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# or wget:
# sh -c "$(wget -qO- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
# wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh
# wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
# sh install.sh
#
# You can tweak the install behavior by setting variables when running the script. For
......@@ -15,17 +15,19 @@
#
# Respects the following environment variables:
# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
# REPO - name of the GitHub repo to install from (default: robbyrussell/oh-my-zsh)
# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
# BRANCH - branch to check out immediately after install (default: master)
#
# Other options:
# CHSH - 'no' means the installer will not change the default shell (default: yes)
# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
#
# You can also pass some arguments to the install script to set some these options:
# --skip-chsh: has the same behavior as setting CHSH to 'no'
# --unattended: sets both CHSH and RUNZSH to 'no'
# --keep-zshrc: sets KEEP_ZSHRC to 'yes'
# For example:
# sh install.sh --unattended
#
......@@ -33,13 +35,14 @@ set -e
# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-robbyrussell/oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
# Other options
CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
command_exists() {
......@@ -90,7 +93,11 @@ setup_ohmyzsh() {
exit 1
fi
git clone --depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
error "git clone of oh-my-zsh repo failed"
exit 1
}
......@@ -107,6 +114,11 @@ setup_zshrc() {
# Must use this exact name so uninstall.sh can find it
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
# Skip this if the user doesn't want to replace an existing .zshrc
if [ $KEEP_ZSHRC = yes ]; then
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
return
fi
if [ -e "$OLD_ZSHRC" ]; then
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
if [ -e "$OLD_OLD_ZSHRC" ]; then
......@@ -125,10 +137,9 @@ setup_zshrc() {
echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc
sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
" ~/.zshrc > ~/.zshrc-omztemp
" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
echo
......@@ -165,6 +176,13 @@ setup_shell() {
*) echo "Invalid choice. Shell change skipped."; return ;;
esac
# Check if we're running on Termux
case "$PREFIX" in
*com.termux*) termux=true; zsh=zsh ;;
*) termux=false ;;
esac
if [ "$termux" != true ]; then
# Test for the right location of the "shells" file
if [ -f /etc/shells ]; then
shells_file=/etc/shells
......@@ -185,9 +203,10 @@ setup_shell() {
return
fi
fi
fi
# We're going to change the default shell, so back up the current one
if [ -n $SHELL ]; then
if [ -n "$SHELL" ]; then
echo $SHELL > ~/.shell.pre-oh-my-zsh
else
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
......@@ -216,6 +235,7 @@ main() {
case $1 in
--unattended) RUNZSH=no; CHSH=no ;;
--skip-chsh) CHSH=no ;;
--keep-zshrc) KEEP_ZSHRC=yes ;;
esac
shift
done
......
......@@ -25,12 +25,8 @@ if [ -e "$ZSHRC_ORIG" ]; then
echo "Your original zsh config was restored."
fi
if hash chsh >/dev/null 2>&1; then
if [ -f ~/.shell.pre-oh-my-zsh ]; then
if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then
old_shell=$(cat ~/.shell.pre-oh-my-zsh)
else
old_shell=/bin/bash
fi
echo "Switching your shell back to '$old_shell':"
if chsh -s "$old_shell"; then
rm -f ~/.shell.pre-oh-my-zsh
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment