updated folder organization
This commit is contained in:
parent
5acb272342
commit
15cf525fbf
36 changed files with 121 additions and 35 deletions
2
cfg/zsh/cfg.d/functions/cnf.zsh
Normal file
2
cfg/zsh/cfg.d/functions/cnf.zsh
Normal file
|
@ -0,0 +1,2 @@
|
|||
[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
|
||||
[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
|
1
cfg/zsh/cfg.d/functions/dircolors.zsh
Normal file
1
cfg/zsh/cfg.d/functions/dircolors.zsh
Normal file
|
@ -0,0 +1 @@
|
|||
eval `dircolors ${DOTCFG}/dir/cfg`
|
72
cfg/zsh/cfg.d/functions/extract.zsh
Normal file
72
cfg/zsh/cfg.d/functions/extract.zsh
Normal file
|
@ -0,0 +1,72 @@
|
|||
alias x=extract
|
||||
|
||||
extract() {
|
||||
local remove_archive
|
||||
local success
|
||||
local extract_dir
|
||||
|
||||
if (( $# == 0 )); then
|
||||
cat <<-'EOF' >&2
|
||||
Usage: extract [-option] [file ...]
|
||||
|
||||
Options:
|
||||
-r, --remove Remove archive.
|
||||
EOF
|
||||
fi
|
||||
|
||||
remove_archive=1
|
||||
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
|
||||
remove_archive=0
|
||||
shift
|
||||
fi
|
||||
|
||||
while (( $# > 0 )); do
|
||||
if [[ ! -f "$1" ]]; then
|
||||
echo "extract: '$1' is not a valid file" >&2
|
||||
shift
|
||||
continue
|
||||
fi
|
||||
|
||||
success=0
|
||||
extract_dir="${1:t:r}"
|
||||
case "$1" in
|
||||
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
|
||||
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
|
||||
(*.tar.xz|*.txz)
|
||||
tar --xz --help &> /dev/null \
|
||||
&& tar --xz -xvf "$1" \
|
||||
|| xzcat "$1" | tar xvf - ;;
|
||||
(*.tar.zma|*.tlz)
|
||||
tar --lzma --help &> /dev/null \
|
||||
&& tar --lzma -xvf "$1" \
|
||||
|| lzcat "$1" | tar xvf - ;;
|
||||
(*.tar) tar xvf "$1" ;;
|
||||
(*.gz) (( $+commands[pigz] )) && pigz -d "$1" || gunzip "$1" ;;
|
||||
(*.bz2) bunzip2 "$1" ;;
|
||||
(*.xz) unxz "$1" ;;
|
||||
(*.lzma) unlzma "$1" ;;
|
||||
(*.Z) uncompress "$1" ;;
|
||||
(*.zip|*.war|*.jar|*.sublime-package|*.ipsw|*.xpi|*.apk) unzip "$1" -d $extract_dir ;;
|
||||
(*.rar) unrar x -ad "$1" ;;
|
||||
(*.7z) 7za x "$1" ;;
|
||||
(*.deb)
|
||||
mkdir -p "$extract_dir/control"
|
||||
mkdir -p "$extract_dir/data"
|
||||
cd "$extract_dir"; ar vx "../${1}" > /dev/null
|
||||
cd control; tar xzvf ../control.tar.gz
|
||||
cd ../data; extract ../data.tar.*
|
||||
cd ..; rm *.tar.* debian-binary
|
||||
cd ..
|
||||
;;
|
||||
(*)
|
||||
echo "extract: '$1' cannot be extracted" >&2
|
||||
success=1
|
||||
;;
|
||||
esac
|
||||
|
||||
(( success = $success > 0 ? $success : $? ))
|
||||
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
3
cfg/zsh/cfg.d/functions/fixatwork.zsh
Normal file
3
cfg/zsh/cfg.d/functions/fixatwork.zsh
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Fix MobaXterm Home/End key with ZSH
|
||||
bindkey '^[[H' beginning-of-line
|
||||
bindkey '^[[F' end-of-line
|
2
cfg/zsh/cfg.d/functions/fzf.zsh
Normal file
2
cfg/zsh/cfg.d/functions/fzf.zsh
Normal file
|
@ -0,0 +1,2 @@
|
|||
[[ $- == *i* ]] && source "/usr/share/fzf/completion.zsh" 2> /dev/null
|
||||
source "/usr/share/fzf/key-bindings.zsh"
|
242
cfg/zsh/cfg.d/functions/git.zsh
Normal file
242
cfg/zsh/cfg.d/functions/git.zsh
Normal file
|
@ -0,0 +1,242 @@
|
|||
# Query/use custom command for `git`.
|
||||
zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd
|
||||
: ${_omz_git_git_cmd:=git}
|
||||
|
||||
#
|
||||
# Functions
|
||||
#
|
||||
|
||||
# The name of the current branch
|
||||
# Back-compatibility wrapper for when this function was defined here in
|
||||
# the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
|
||||
# to fix the core -> git plugin dependency.
|
||||
function current_branch() {
|
||||
git_current_branch
|
||||
}
|
||||
# The list of remotes
|
||||
function current_repository() {
|
||||
if ! $_omz_git_git_cmd rev-parse --is-inside-work-tree &> /dev/null; then
|
||||
return
|
||||
fi
|
||||
echo $($_omz_git_git_cmd remote -v | cut -d':' -f 2)
|
||||
}
|
||||
# Pretty log messages
|
||||
function _git_log_prettily(){
|
||||
if ! [ -z $1 ]; then
|
||||
git log --pretty=$1
|
||||
fi
|
||||
}
|
||||
# Warn if the current branch is a WIP
|
||||
function work_in_progress() {
|
||||
if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
|
||||
echo "WIP!!"
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Aliases
|
||||
# (sorted alphabetically)
|
||||
#
|
||||
|
||||
alias g='git'
|
||||
|
||||
alias ga='git add'
|
||||
alias gaa='git add --all'
|
||||
alias gapa='git add --patch'
|
||||
alias gau='git add --update'
|
||||
|
||||
alias gb='git branch'
|
||||
alias gba='git branch -a'
|
||||
alias gbd='git branch -d'
|
||||
alias gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
|
||||
alias gbl='git blame -b -w'
|
||||
alias gbnm='git branch --no-merged'
|
||||
alias gbr='git branch --remote'
|
||||
alias gbs='git bisect'
|
||||
alias gbsb='git bisect bad'
|
||||
alias gbsg='git bisect good'
|
||||
alias gbsr='git bisect reset'
|
||||
alias gbss='git bisect start'
|
||||
|
||||
alias gc='git commit -v'
|
||||
alias gc!='git commit -v --amend'
|
||||
alias gcn!='git commit -v --no-edit --amend'
|
||||
alias gca='git commit -v -a'
|
||||
alias gca!='git commit -v -a --amend'
|
||||
alias gcan!='git commit -v -a --no-edit --amend'
|
||||
alias gcans!='git commit -v -a -s --no-edit --amend'
|
||||
alias gcam='git commit -a -m'
|
||||
alias gcsm='git commit -s -m'
|
||||
alias gcb='git checkout -b'
|
||||
alias gcf='git config --list'
|
||||
alias gcl='git clone --recursive'
|
||||
alias gclean='git clean -fd'
|
||||
alias gpristine='git reset --hard && git clean -dfx'
|
||||
alias gcm='git checkout master'
|
||||
alias gcd='git checkout develop'
|
||||
alias gcmsg='git commit -m'
|
||||
alias gco='git checkout'
|
||||
alias gcount='git shortlog -sn'
|
||||
compdef _git gcount
|
||||
alias gcp='git cherry-pick'
|
||||
alias gcpa='git cherry-pick --abort'
|
||||
alias gcpc='git cherry-pick --continue'
|
||||
alias gcs='git commit -S'
|
||||
|
||||
alias gd='git diff'
|
||||
alias gdca='git diff --cached'
|
||||
alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
|
||||
alias gdt='git diff-tree --no-commit-id --name-only -r'
|
||||
alias gdw='git diff --word-diff'
|
||||
|
||||
gdv() { git diff -w "$@" | view - }
|
||||
compdef _git gdv=git-diff
|
||||
|
||||
alias gf='git fetch'
|
||||
alias gfa='git fetch --all --prune'
|
||||
alias gfo='git fetch origin'
|
||||
|
||||
function gfg() { git ls-files | grep $@ }
|
||||
compdef _grep gfg
|
||||
|
||||
alias gg='git gui citool'
|
||||
alias gga='git gui citool --amend'
|
||||
|
||||
ggf() {
|
||||
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
|
||||
git push --force origin "${b:=$1}"
|
||||
}
|
||||
compdef _git ggf=git-checkout
|
||||
|
||||
ggl() {
|
||||
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
|
||||
git pull origin "${*}"
|
||||
else
|
||||
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
|
||||
git pull origin "${b:=$1}"
|
||||
fi
|
||||
}
|
||||
compdef _git ggl=git-checkout
|
||||
|
||||
ggp() {
|
||||
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
|
||||
git push origin "${*}"
|
||||
else
|
||||
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
|
||||
git push origin "${b:=$1}"
|
||||
fi
|
||||
}
|
||||
compdef _git ggp=git-checkout
|
||||
|
||||
ggpnp() {
|
||||
if [[ "$#" == 0 ]]; then
|
||||
ggl && ggp
|
||||
else
|
||||
ggl "${*}" && ggp "${*}"
|
||||
fi
|
||||
}
|
||||
compdef _git ggpnp=git-checkout
|
||||
|
||||
ggu() {
|
||||
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
|
||||
git pull --rebase origin "${b:=$1}"
|
||||
}
|
||||
compdef _git ggu=git-checkout
|
||||
|
||||
alias ggpur='ggu'
|
||||
compdef _git ggpur=git-checkout
|
||||
|
||||
alias ggpull='git pull origin $(git_current_branch)'
|
||||
compdef _git ggpull=git-checkout
|
||||
|
||||
alias ggpush='git push origin $(git_current_branch)'
|
||||
compdef _git ggpush=git-checkout
|
||||
|
||||
alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
|
||||
alias gpsup='git push --set-upstream origin $(git_current_branch)'
|
||||
|
||||
alias ghh='git help'
|
||||
|
||||
alias gignore='git update-index --assume-unchanged'
|
||||
alias gignored='git ls-files -v | grep "^[[:lower:]]"'
|
||||
alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
|
||||
compdef _git git-svn-dcommit-push=git
|
||||
|
||||
alias gk='\gitk --all --branches'
|
||||
compdef _git gk='gitk'
|
||||
alias gke='\gitk --all $(git log -g --pretty=%h)'
|
||||
compdef _git gke='gitk'
|
||||
|
||||
alias gl='git pull'
|
||||
alias glg='git log --stat'
|
||||
alias glgp='git log --stat -p'
|
||||
alias glgg='git log --graph'
|
||||
alias glgga='git log --graph --decorate --all'
|
||||
alias glgm='git log --graph --max-count=10'
|
||||
alias glo='git log --oneline --decorate'
|
||||
alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
||||
alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
|
||||
alias glog='git log --oneline --decorate --graph'
|
||||
alias gloga='git log --oneline --decorate --graph --all'
|
||||
alias glp="_git_log_prettily"
|
||||
compdef _git glp=git-log
|
||||
|
||||
alias gm='git merge'
|
||||
alias gmom='git merge origin/master'
|
||||
alias gmt='git mergetool --no-prompt'
|
||||
alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
|
||||
alias gmum='git merge upstream/master'
|
||||
|
||||
alias gp='git push'
|
||||
alias gpd='git push --dry-run'
|
||||
alias gpoat='git push origin --all && git push origin --tags'
|
||||
compdef _git gpoat=git-push
|
||||
alias gpu='git push upstream'
|
||||
alias gpv='git push -v'
|
||||
|
||||
alias gr='git remote'
|
||||
alias gra='git remote add'
|
||||
alias grb='git rebase'
|
||||
alias grba='git rebase --abort'
|
||||
alias grbc='git rebase --continue'
|
||||
alias grbi='git rebase -i'
|
||||
alias grbm='git rebase master'
|
||||
alias grbs='git rebase --skip'
|
||||
alias grh='git reset HEAD'
|
||||
alias grhh='git reset HEAD --hard'
|
||||
alias grmv='git remote rename'
|
||||
alias grrm='git remote remove'
|
||||
alias grset='git remote set-url'
|
||||
alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
|
||||
alias gru='git reset --'
|
||||
alias grup='git remote update'
|
||||
alias grv='git remote -v'
|
||||
|
||||
alias gsb='git status -sb'
|
||||
alias gsd='git svn dcommit'
|
||||
alias gsi='git submodule init'
|
||||
alias gsps='git show --pretty=short --show-signature'
|
||||
alias gsr='git svn rebase'
|
||||
alias gss='git status -s'
|
||||
alias gst='git status'
|
||||
alias gsta='git stash save'
|
||||
alias gstaa='git stash apply'
|
||||
alias gstc='git stash clear'
|
||||
alias gstd='git stash drop'
|
||||
alias gstl='git stash list'
|
||||
alias gstp='git stash pop'
|
||||
alias gsts='git stash show --text'
|
||||
alias gsu='git submodule update'
|
||||
|
||||
alias gts='git tag -s'
|
||||
alias gtv='git tag | sort -V'
|
||||
|
||||
alias gunignore='git update-index --no-assume-unchanged'
|
||||
alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
|
||||
alias gup='git pull --rebase'
|
||||
alias gupv='git pull --rebase -v'
|
||||
alias glum='git pull upstream master'
|
||||
|
||||
alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
|
||||
alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'
|
||||
|
56
cfg/zsh/cfg.d/functions/gitignore.zsh
Normal file
56
cfg/zsh/cfg.d/functions/gitignore.zsh
Normal file
|
@ -0,0 +1,56 @@
|
|||
export ZSH_PLUGIN_GITIGNORE_PATH=$(dirname $0)
|
||||
export ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS=${DOTLIB}/gitignore
|
||||
|
||||
function gie () {
|
||||
${EDITOR} .gitignore
|
||||
}
|
||||
|
||||
function gi() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat .gitignore
|
||||
return 0
|
||||
fi
|
||||
|
||||
for t in $*; do
|
||||
get_gitignore_template $t
|
||||
done
|
||||
}
|
||||
|
||||
function gii() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat .gitignore
|
||||
return 0
|
||||
fi
|
||||
|
||||
# if NOCLOBBER option is setted
|
||||
gi $* >>! .gitignore
|
||||
}
|
||||
|
||||
function get_gitignore_template() {
|
||||
for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do;
|
||||
local file=$(find $tpath -iname "$1.gitignore")
|
||||
if [[ ! -z $file ]]; then
|
||||
comment=$(basename $file | sed -e 's/.gitignore$//')
|
||||
echo
|
||||
echo "### $comment"
|
||||
cat $file
|
||||
break;
|
||||
fi
|
||||
done;
|
||||
}
|
||||
|
||||
_gitignore_get_template_list() {
|
||||
(for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do; find $tpath -type f -name "*.gitignore"; done) \
|
||||
| xargs -n 1 basename \
|
||||
| sed -e 's/.gitignore$//' -e 's/\(.*\)/\L\1/' \
|
||||
| sort -u
|
||||
}
|
||||
|
||||
_gitignore () {
|
||||
compset -P '*,'
|
||||
compadd -S '' `_gitignore_get_template_list`
|
||||
}
|
||||
|
||||
compdef _gitignore gi
|
||||
compdef _gitignore gii
|
||||
|
99
cfg/zsh/cfg.d/functions/tmux.zsh
Normal file
99
cfg/zsh/cfg.d/functions/tmux.zsh
Normal file
|
@ -0,0 +1,99 @@
|
|||
#
|
||||
# Aliases
|
||||
#
|
||||
|
||||
alias ta='tmux attach -t'
|
||||
alias tad='tmux attach -d -t'
|
||||
alias ts='tmux new-session -s'
|
||||
alias tl='tmux list-sessions'
|
||||
alias tksv='tmux kill-server'
|
||||
alias tkss='tmux kill-session -t'
|
||||
|
||||
# Only run if tmux is actually installed
|
||||
if which tmux &> /dev/null
|
||||
then
|
||||
# Configuration variables
|
||||
#
|
||||
# Automatically start tmux
|
||||
[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
|
||||
# Only autostart once. If set to false, tmux will attempt to
|
||||
# autostart every time your zsh configs are reloaded.
|
||||
[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
|
||||
# Automatically connect to a previous session if it exists
|
||||
[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
|
||||
# Automatically close the terminal when tmux exits
|
||||
[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
|
||||
# Set term to screen or screen-256color based on current terminal support
|
||||
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
|
||||
# Set '-CC' option for iTerm2 tmux integration
|
||||
[[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false
|
||||
# The TERM to use for non-256 color terminals.
|
||||
# Tmux states this should be screen, but you may need to change it on
|
||||
# systems without the proper terminfo
|
||||
[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen"
|
||||
# The TERM to use for 256 color terminals.
|
||||
# Tmux states this should be screen-256color, but you may need to change it on
|
||||
# systems without the proper terminfo
|
||||
[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
|
||||
|
||||
|
||||
# Get the absolute path to the current directory
|
||||
local zsh_tmux_plugin_path=${DOTCFG}/tmux
|
||||
|
||||
# Determine if the terminal supports 256 colors
|
||||
if [[ `tput colors` == "256" ]]
|
||||
then
|
||||
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
|
||||
else
|
||||
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
|
||||
fi
|
||||
|
||||
# Set the correct local config file to use.
|
||||
if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
|
||||
then
|
||||
#use this when they have a ~/.tmux.conf
|
||||
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
|
||||
else
|
||||
#use this when they don't have a ~/.tmux.conf
|
||||
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
|
||||
fi
|
||||
|
||||
# Wrapper function for tmux.
|
||||
function _zsh_tmux_plugin_run()
|
||||
{
|
||||
# We have other arguments, just run them
|
||||
if [[ -n "$@" ]]
|
||||
then
|
||||
\tmux $@
|
||||
# Try to connect to an existing session.
|
||||
elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
|
||||
then
|
||||
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session
|
||||
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
|
||||
# Just run tmux, fixing the TERM variable if requested.
|
||||
else
|
||||
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`
|
||||
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
|
||||
fi
|
||||
}
|
||||
|
||||
# Use the completions for tmux for our function
|
||||
compdef _tmux _zsh_tmux_plugin_run
|
||||
|
||||
# Alias tmux to our wrapper function.
|
||||
alias tmux=_zsh_tmux_plugin_run
|
||||
|
||||
# Autostart if not already in tmux and enabled.
|
||||
if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
|
||||
then
|
||||
# Actually don't autostart if we already did and multiple autostarts are disabled.
|
||||
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
|
||||
then
|
||||
export ZSH_TMUX_AUTOSTARTED=true
|
||||
_zsh_tmux_plugin_run
|
||||
fi
|
||||
fi
|
||||
else
|
||||
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
|
||||
fi
|
||||
|
54
cfg/zsh/cfg.d/functions/transfer.zsh
Normal file
54
cfg/zsh/cfg.d/functions/transfer.zsh
Normal file
|
@ -0,0 +1,54 @@
|
|||
#
|
||||
# Defines transfer alias and provides easy command line file and folder sharing.
|
||||
#
|
||||
# Authors:
|
||||
# Remco Verhoef <remco@dutchcoders.io>
|
||||
#
|
||||
|
||||
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
|
||||
# zip directory and transfer
|
||||
zipfile=$( mktemp -t transferXXX.zip )
|
||||
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
|
||||
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
|
||||
rm -f $zipfile
|
||||
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
|
||||
}
|
||||
|
81
cfg/zsh/cfg.d/functions/up.zsh
Normal file
81
cfg/zsh/cfg.d/functions/up.zsh
Normal file
|
@ -0,0 +1,81 @@
|
|||
__updir() {
|
||||
if [[ "$1" == "/" || -z "$1" || -z "$2" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local p="$(dirname $1)"
|
||||
local a="$(basename $p)"
|
||||
local b="$(basename $2)"
|
||||
|
||||
if [[ -z "$a" || -z "$b" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$a" == "$b"* ]]; then
|
||||
echo "$p"
|
||||
return
|
||||
fi
|
||||
|
||||
__updir "$p" "$2"
|
||||
}
|
||||
|
||||
__upnum() {
|
||||
if [[ -z "$1" || -z "$2" || ! "$2" =~ ^[0-9]+$ ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local p="$1"
|
||||
local i="$2"
|
||||
|
||||
while (( i-- )); do
|
||||
p="$(dirname $p)"
|
||||
done
|
||||
|
||||
echo "$p"
|
||||
}
|
||||
|
||||
_up() {
|
||||
local p="$(dirname $PWD)"
|
||||
local w="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
COMPREPLY=( $(IFS=';' compgen -S/ -W "${p//\//;}" -- "$w") )
|
||||
}
|
||||
|
||||
up() {
|
||||
# up one
|
||||
if (( ! $# )); then
|
||||
cd ..
|
||||
return
|
||||
fi
|
||||
|
||||
# up dir
|
||||
local d="$(__updir "$PWD" "$1")"
|
||||
|
||||
if [[ -d "$d" ]]; then
|
||||
cd "$d"
|
||||
return
|
||||
fi
|
||||
|
||||
# up num
|
||||
local n="$(__upnum "$PWD" "$1")"
|
||||
|
||||
if [[ -d "$n" ]]; then
|
||||
cd "$n"
|
||||
return
|
||||
fi
|
||||
|
||||
# fallback
|
||||
if [[ $1 == - || -d $1 ]]; then
|
||||
cd $1
|
||||
return
|
||||
fi
|
||||
|
||||
# usage
|
||||
echo -e "usage: up [dir|num|-]\npwd: $PWD"
|
||||
}
|
||||
|
||||
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
|
||||
# tab-completion
|
||||
complete -o nospace -F _up up
|
137
cfg/zsh/cfg.d/functions/zshmarks.zsh
Normal file
137
cfg/zsh/cfg.d/functions/zshmarks.zsh
Normal file
|
@ -0,0 +1,137 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
# FILE: zshmarks.plugin.zsh
|
||||
# DESCRIPTION: oh-my-zsh plugin file.
|
||||
# AUTHOR: Jocelyn Mallon
|
||||
# VERSION: 1.7.0
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Set BOOKMARKS_FILE if it doesn't exist to the default.
|
||||
# Allows for a user-configured BOOKMARKS_FILE.
|
||||
if [[ -z $BOOKMARKS_FILE ]] ; then
|
||||
export BOOKMARKS_FILE=${DOTLIB}/bookmarks
|
||||
fi
|
||||
|
||||
# Check if $BOOKMARKS_FILE is a symlink.
|
||||
if [[ -L $BOOKMARKS_FILE ]]; then
|
||||
BOOKMARKS_FILE=$(readlink $BOOKMARKS_FILE)
|
||||
fi
|
||||
|
||||
# Create bookmarks_file it if it doesn't exist
|
||||
if [[ ! -f $BOOKMARKS_FILE ]]; then
|
||||
touch $BOOKMARKS_FILE
|
||||
fi
|
||||
|
||||
_zshmarks_move_to_trash(){
|
||||
if [[ $(uname) == "Linux"* || $(uname) == "FreeBSD"* ]]; then
|
||||
label=`date +%s`
|
||||
mkdir -p ~/.local/share/Trash/info ~/.local/share/Trash/files
|
||||
\mv "${BOOKMARKS_FILE}.bak" ~/.local/share/Trash/files/bookmarks-$label
|
||||
echo "[Trash Info]
|
||||
Path=/home/"$USER"/.bookmarks
|
||||
DeletionDate="`date +"%Y-%m-%dT%H:%M:%S"`"
|
||||
">~/.local/share/Trash/info/bookmarks-$label.trashinfo
|
||||
elif [[ $(uname) = "Darwin" ]]; then
|
||||
\mv "${BOOKMARKS_FILE}.bak" ~/.Trash/"bookmarks"$(date +%H-%M-%S)
|
||||
else
|
||||
\rm -f "${BOOKMARKS_FILE}.bak"
|
||||
fi
|
||||
}
|
||||
|
||||
function bookmark() {
|
||||
local bookmark_name=$1
|
||||
if [[ -z $bookmark_name ]]; then
|
||||
bookmark_name="${PWD##*/}"
|
||||
fi
|
||||
cur_dir="$(pwd)"
|
||||
# Replace /home/uname with $HOME
|
||||
if [[ "$cur_dir" =~ ^"$HOME"(/|$) ]]; then
|
||||
cur_dir="\$HOME${cur_dir#$HOME}"
|
||||
fi
|
||||
# Store the bookmark as folder|name
|
||||
bookmark="$cur_dir|$bookmark_name"
|
||||
if [[ -z $(grep "$bookmark" $BOOKMARKS_FILE 2>/dev/null) ]]; then
|
||||
echo $bookmark >> $BOOKMARKS_FILE
|
||||
echo "Bookmark '$bookmark_name' saved"
|
||||
else
|
||||
echo "Bookmark already existed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
__zshmarks_zgrep() {
|
||||
local outvar="$1"; shift
|
||||
local pattern="$1"
|
||||
local filename="$2"
|
||||
local file_contents="$(<"$filename")"
|
||||
local file_lines; file_lines=(${(f)file_contents})
|
||||
for line in "${file_lines[@]}"; do
|
||||
if [[ "$line" =~ "$pattern" ]]; then
|
||||
eval "$outvar=\"$line\""
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function jump() {
|
||||
local bookmark_name=$1
|
||||
local bookmark
|
||||
if ! __zshmarks_zgrep bookmark "\\|$bookmark_name\$" "$BOOKMARKS_FILE"; then
|
||||
echo "Invalid name, please provide a valid bookmark name. For example:"
|
||||
echo " jump foo"
|
||||
echo
|
||||
echo "To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):"
|
||||
echo " bookmark foo"
|
||||
return 1
|
||||
else
|
||||
local dir="${bookmark%%|*}"
|
||||
eval "cd \"${dir}\""
|
||||
fi
|
||||
}
|
||||
|
||||
# Show a list of the bookmarks
|
||||
function showmarks() {
|
||||
local bookmark_file="$(<"$BOOKMARKS_FILE")"
|
||||
local bookmark_array; bookmark_array=(${(f)bookmark_file});
|
||||
local bookmark_name bookmark_path bookmark_line
|
||||
if [[ $# -eq 1 ]]; then
|
||||
bookmark_name="*\|${1}"
|
||||
bookmark_line=${bookmark_array[(r)$bookmark_name]}
|
||||
bookmark_path="${bookmark_line%%|*}"
|
||||
bookmark_path="${bookmark_path/\$HOME/~}"
|
||||
printf "%s \n" $bookmark_path
|
||||
else
|
||||
for bookmark_line in $bookmark_array; do
|
||||
bookmark_path="${bookmark_line%%|*}"
|
||||
bookmark_path="${bookmark_path/\$HOME/~}"
|
||||
bookmark_name="${bookmark_line#*|}"
|
||||
printf "%s\t\t%s\n" "$bookmark_name" "$bookmark_path"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Delete a bookmark
|
||||
function deletemark() {
|
||||
local bookmark_name=$1
|
||||
if [[ -z $bookmark_name ]]; then
|
||||
printf "%s \n" "Please provide a name for your bookmark to delete. For example:"
|
||||
printf "\t%s \n" "deletemark foo"
|
||||
return 1
|
||||
else
|
||||
local bookmark_line bookmark_search
|
||||
local bookmark_file="$(<"$BOOKMARKS_FILE")"
|
||||
local bookmark_array; bookmark_array=(${(f)bookmark_file});
|
||||
bookmark_search="*\|${bookmark_name}"
|
||||
if [[ -z ${bookmark_array[(r)$bookmark_search]} ]]; then
|
||||
eval "printf '%s\n' \"'${bookmark_name}' not found, skipping.\""
|
||||
else
|
||||
\cp "${BOOKMARKS_FILE}" "${BOOKMARKS_FILE}.bak"
|
||||
bookmark_line=${bookmark_array[(r)$bookmark_search]}
|
||||
bookmark_array=(${bookmark_array[@]/$bookmark_line})
|
||||
eval "printf '%s\n' \"\${bookmark_array[@]}\"" >! $BOOKMARKS_FILE
|
||||
_zshmarks_move_to_trash
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue