Merge pull request #1 from robbyrussell/master

update
This commit is contained in:
Erwan ROUSSEL 2018-05-26 22:07:55 +02:00 committed by GitHub
commit e6a0d890ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 167 additions and 81 deletions

View file

@ -2,10 +2,6 @@
# insecure ownership or permissions) by:
#
# * Human-readably notifying the user of these insecurities.
# * Moving away all existing completion caches to a temporary directory. Since
# any of these caches may have been generated from insecure directories, they
# are all suspect now. Failing to do so typically causes subsequent compinit()
# calls to fail with "command not found: compdef" errors. (That's bad.)
function handle_completion_insecurities() {
# List of the absolute paths of all unique insecure directories, split on
# newline from compaudit()'s output resembling:
@ -22,39 +18,27 @@ function handle_completion_insecurities() {
insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} )
# If no such directories exist, get us out of here.
if (( ! ${#insecure_dirs} )); then
print "[oh-my-zsh] No insecure completion-dependent directories detected."
return
fi
(( ! ${#insecure_dirs} )) && return
# List ownership and permissions of all insecure directories.
print "[oh-my-zsh] Insecure completion-dependent directories detected:"
ls -ld "${(@)insecure_dirs}"
print "[oh-my-zsh] For safety, completions will be disabled until you manually fix all"
print "[oh-my-zsh] insecure directory permissions and ownership and restart oh-my-zsh."
print "[oh-my-zsh] See the above list for directories with group or other writability.\n"
# Locally enable the "NULL_GLOB" option, thus removing unmatched filename
# globs from argument lists *AND* printing no warning when doing so. Failing
# to do so prints an unreadable warning if no completion caches exist below.
setopt local_options null_glob
cat <<EOD
# List of the absolute paths of all unique existing completion caches.
local -aU zcompdump_files
zcompdump_files=( "${ZSH_COMPDUMP}"(.) "${ZDOTDIR:-${HOME}}"/.zcompdump* )
[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.
# Move such caches to a temporary directory.
if (( ${#zcompdump_files} )); then
# Absolute path of the directory to which such files will be moved.
local ZSH_ZCOMPDUMP_BAD_DIR="${ZSH_CACHE_DIR}/zcompdump-bad"
[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh] compaudit | xargs chmod g-w,o-w
# List such files first.
print "[oh-my-zsh] Insecure completion caches also detected:"
ls -l "${(@)zcompdump_files}"
[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.
# For safety, move rather than permanently remove such files.
print "[oh-my-zsh] Moving to \"${ZSH_ZCOMPDUMP_BAD_DIR}/\"...\n"
mkdir -p "${ZSH_ZCOMPDUMP_BAD_DIR}"
mv "${(@)zcompdump_files}" "${ZSH_ZCOMPDUMP_BAD_DIR}/"
fi
EOD
}

View file

@ -28,7 +28,3 @@ alias lsa='ls -lah'
alias l='ls -lah'
alias ll='ls -lh'
alias la='ls -lAh'
# Push and pop directories on directory stack
alias pu='pushd'
alias po='popd'

View file

@ -63,15 +63,14 @@ if [ -z "$ZSH_COMPDUMP" ]; then
fi
if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
# If completion insecurities exist, warn the user without enabling completions.
# If completion insecurities exist, warn the user
if ! compaudit &>/dev/null; then
# This function resides in the "lib/compfix.zsh" script sourced above.
handle_completion_insecurities
# Else, enable and cache completions to the desired file.
else
compinit -d "${ZSH_COMPDUMP}"
fi
# Load only from secure directories
compinit -i -d "${ZSH_COMPDUMP}"
else
# If the user wants it, load from all found directories
compinit -u -d "${ZSH_COMPDUMP}"
fi

View file

@ -1,9 +1,13 @@
# Autocompletion for kubectl, the command line interface for Kubernetes
#
# Author: https://github.com/pstadler
if (( $+commands[kubectl] )); then
__KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then
kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
fi
[[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
unset __KUBECTL_COMPLETION_FILE
fi
# This command is used ALOT both below and in daily life

View file

@ -11,7 +11,21 @@ This plugin automatically registers npx command-not-found handler if `npx` exist
plugins=(.... npx)
```
- Globally install npx binary (you need node.js installed too!)
- Globally install npx binary (npx will be auto installed with recent versions of Node.js)
```bash
sudo npm install -g npx
```
```
## Note
The shell auto-fallback doesn't auto-install plain packages. In order to get it to install something, you need to add `@`:
```
➜ jasmine@latest # or just `jasmine@`
npx: installed 13 in 1.896s
Randomized with seed 54385
Started
```
It does it this way so folks using the fallback don't accidentally try to install regular typoes.

View file

@ -88,24 +88,18 @@ shrink_path () {
if (( named )) {
for part in ${(k)nameddirs}; {
[[ $dir == ${nameddirs[$part]}(/*|) ]] && dir=${dir/${nameddirs[$part]}/\~$part}
[[ $dir == ${nameddirs[$part]}(/*|) ]] && dir=${dir/#${nameddirs[$part]}/\~$part}
}
}
(( tilde )) && dir=${dir/$HOME/\~}
(( tilde )) && dir=${dir/#$HOME/\~}
tree=(${(s:/:)dir})
(
# unset chpwd_functions since we'll be calling `cd` and don't
# want any side-effects (eg., if the user was using auto-ls)
chpwd_functions=()
# unset chpwd since even if chpwd_functions is (), zsh will
# attempt to execute chpwd
unfunction chpwd 2> /dev/null
if [[ $tree[1] == \~* ]] {
cd ${~tree[1]}
cd -q ${~tree[1]}
result=$tree[1]
shift tree
} else {
cd /
cd -q /
}
for dir in $tree; {
if (( lastfull && $#tree == 1 )) {
@ -122,7 +116,7 @@ shrink_path () {
(( short )) && break
done
result+="/$part"
cd $dir
cd -q $dir
shift tree
}
echo ${result:-/}

View file

@ -0,0 +1,24 @@
# `transfer` plugin
[`transfer.sh`](https://transfer.sh) is an easy to use file sharing service from the command line
## Usage
Add `transfer` to your plugins array in your zshrc file:
```zsh
plugins=(... transfer)
```
Then you can:
- transfer a file:
```zsh
transfer file.txt
```
- transfer a whole directory (it will be automatically compressed):
```zsh
transfer directory/
```

View file

@ -0,0 +1,67 @@
# transfer.sh Easy file sharing from the command line
# transfer Plugin
# Usage Example :
# > transfer file.txt
# > transfer directory/
# Author:
# Remco Verhoef <remco@dutchcoders.io>
# https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
# Modified to use tar command instead of zip
#
curl --version 2>&1 > /dev/null
if [ $? -ne 0 ]; then
echo "Could not find curl."
return 1
fi
transfer() {
# check arguments
if [ $# -eq 0 ];
then
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
fi
# get temporarily filename, output is written to this file show progress can be showed
tmpfile=$( mktemp -t transferXXX )
# upload stdin or file
file=$1
if tty -s;
then
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
if [ ! -e $file ];
then
echo "File $file doesn't exists."
return 1
fi
if [ -d $file ];
then
echo $file
# tar directory and transfer
tarfile=$( mktemp -t transferXXX.tar.gz )
cd $(dirname $file) && tar -czf $tarfile $(basename $file)
curl --progress-bar --upload-file "$tarfile" "https://transfer.sh/$basefile.tar.gz" >> $tmpfile
rm -f $tarfile
else
# transfer file
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
fi
else
# transfer pipe
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
fi
# cat output link
cat $tmpfile
# cleanup
rm -f $tmpfile
}

View file

@ -1,6 +1,14 @@
virtualenvwrapper='virtualenvwrapper.sh'
virtualenvwrapper_lazy='virtualenvwrapper_lazy.sh'
if (( $+commands[$virtualenvwrapper] )); then
if (( $+commands[$virtualenvwrapper_lazy] )); then
function {
setopt local_options
unsetopt equals
virtualenvwrapper=${${virtualenvwrapper_lazy}:c}
source ${${virtualenvwrapper_lazy}:c}
}
elif (( $+commands[$virtualenvwrapper] )); then
function {
setopt local_options
unsetopt equals

42
themes/agnoster.zsh-theme Executable file → Normal file
View file

@ -29,7 +29,6 @@
# A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE'
zmodload zsh/parameter
# Special Powerline characters
@ -56,23 +55,23 @@ prompt_segment() {
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
PROMPT+=" %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
PROMPT+="%{$bg%}%{$fg%} "
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && PROMPT+=$3
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
PROMPT+=" %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
PROMPT+="%{%k%}"
echo -n "%{%k%}"
fi
PROMPT+="%{%f%}"
CURRENT_BG='NONE'
echo -n "%{%f%}"
CURRENT_BG=''
}
### Prompt components
@ -124,7 +123,7 @@ prompt_git() {
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info
PROMPT+="${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
fi
}
@ -136,15 +135,15 @@ prompt_bzr() {
revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'`
if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black
PROMPT+="bzr@$revision ✚ "
echo -n "bzr@"$revision "✚ "
else
if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black
PROMPT+="bzr@$revision"
echo -n "bzr@"$revision
else
prompt_segment green black
PROMPT+="bzr@$revision"
echo -n "bzr@"$revision
fi
fi
fi
@ -158,30 +157,30 @@ prompt_hg() {
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
prompt_segment red white
st=' ±'
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
prompt_segment yellow black
st=' ±'
st='±'
else
# if working copy is clean
prompt_segment green black
fi
PROMPT+="$(hg prompt "☿ {rev}@{branch}")$st"
echo -n $(hg prompt "☿ {rev}@{branch}") $st
else
st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null)
if `hg st | grep -q "^\?"`; then
prompt_segment red black
st=' ±'
st='±'
elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st=' ±'
st='±'
else
prompt_segment green black
fi
PROMPT+="☿ $rev@$branch$st"
echo -n "☿ $rev@$branch" $st
fi
fi
}
@ -208,7 +207,7 @@ prompt_status() {
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ ${#jobstates} -ne 0 ]] && symbols+="%{%F{cyan}%}⚙"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
@ -216,7 +215,6 @@ prompt_status() {
## Main prompt
build_prompt() {
RETVAL=$?
PROMPT='%{%f%b%k%}'
prompt_status
prompt_virtualenv
prompt_context
@ -225,8 +223,6 @@ build_prompt() {
prompt_bzr
prompt_hg
prompt_end
PROMPT+=' '
}
autoload -U add-zsh-hook
add-zsh-hook precmd build_prompt
PROMPT='%{%f%b%k%}$(build_prompt) '