From 05f6bf7007215eb364da9142ff69f66d13a23682 Mon Sep 17 00:00:00 2001 From: "Alexander Gehrke (crater2150)" Date: Fri, 22 Jul 2016 16:01:35 +0200 Subject: [PATCH] Various small additions --- aliases/functions | 81 +++++++++++++++++++++++++++++++++++++- aliases/git | 27 +++++++++++-- aliases/mpd | 8 ++++ compdef/_conf | 3 ++ compdef/_tagsistant-helper | 33 ++++++++++++++++ compdef/_xd | 8 ++++ modules/bindings/init | 4 ++ modules/conf/init | 22 +++++++++++ modules/fuck/init | 3 ++ modules/localrc/init | 10 +++++ zshrc | 14 +++++++ 11 files changed, 208 insertions(+), 5 deletions(-) create mode 100755 aliases/mpd create mode 100644 compdef/_conf create mode 100644 compdef/_tagsistant-helper create mode 100644 compdef/_xd create mode 100755 modules/conf/init create mode 100644 modules/fuck/init create mode 100755 modules/localrc/init diff --git a/aliases/functions b/aliases/functions index 20aebc0..d76b8d8 100644 --- a/aliases/functions +++ b/aliases/functions @@ -4,7 +4,7 @@ # daily use aliases ##############################################################################{{{ -alias ls="ls --color=auto" +alias ls="ls -N --color=auto" alias ll="ls -hl --group-directories-first" alias lll="ls -hla" alias ds="du -sh" @@ -56,6 +56,81 @@ cd(){ # filesystem stuff ##############################################################################{{{ +t=${TAGSISTANT_ROOT:-$HOME/tagged}/store +tagmount() { + tagsistant ${TAGSISTANT_ROOT:-$HOME/tagged} &>/tmp/tagsistant.$USER +} + +tag() { + if [[ -z $2 ]]; then + printf "%s\n" \ + "Usage: tag FILE... [-n name] [-v] [-p] TAG..." \ + "" \ + "Each TAG must end with the @ delimiter component." \ + "Each File must have a name different from a single @" + return 1 + fi + local name preview + + zparseopts -D -E n:=name -name:=name p=preview -preview=preview \ + v=verbose -verbose=verbose + + local sources=() + local tags=() + + for i in "${@}"; do + if [[ ${i:t} == "@" ]]; then + tags+=${i} + else + sources+=${i:A} + fi + done + + for source in "${sources[@]}"; do + for tag in "${tags[@]}"; do + target=~t/$tag + if [[ ! -d $target ]]; then mkdir -p $target; fi + if [[ -n $verbose ]]; then echo "Tagging $source with $tag"; fi + ${=preview:+echo} ln -s $source $target/${name[2]} + done + done +} + +papertag() { + if [[ -z $2 ]]; then + echo "Usage: papertag FILE [-v] [-y YEAR] [AUTHOR...] [:: OTHER TAGS]" + return 1 + fi + + local year + zparseopts -D -E y:=year -year:=year \ + v=verbose -verbose=verbose + + local paper=$1; shift + + tag $verbose $paper paper/@ + if [[ -n "$year" ]]; then + tag $verbose $paper meta:/year/eq/${year[2]}/@/ + fi + while [[ -n $1 ]]; do + local author=$1; shift + if [[ "$author" == "::" ]]; then break; fi + tag $verbose $paper meta:/author/eq/$author/@ + done + for tag in "$@"; do + tag $verbose $paper $tag + done +} + +tcd() { + rpath=$(realpath ~t/$1) + if [[ -d $rpath ]]; then + cd $rpath; + else + cd ${rpath:h} + fi +} + # count files in current or given directory count() { find $1 \( ! -path '*/.*' \) | wc -l @@ -116,7 +191,7 @@ suffix() { alias exifcopy="exiftool -tagsFromFile" photobydate() { - for i in (#i)*.(JPG|CR2); do + for i in ${*:-(#i)*.(JPG|CR2)}; do dir=$(exiftool -p '$DateTimeOriginal' $i | tr ':' '-' | cut -d' ' -f1;) mkdir -p $dir mv ${i:r}.* $dir @@ -160,6 +235,8 @@ svn() { esac } +alias gitv='vim "$(git rev-parse --git-dir)/index" -c "Gitv --all" -c tabonly' + #}}} ################################################################################# diff --git a/aliases/git b/aliases/git index 460ae4f..9bde9cb 100644 --- a/aliases/git +++ b/aliases/git @@ -1,8 +1,8 @@ #!/bin/zsh ginit() { - git init; - git add ${*:-"."}; - git commit -a -m "Initial Commit" + git init; + git add ${*:-"."}; + git commit -a -m "Initial Commit" } gst() { @@ -27,3 +27,24 @@ alias gco="git checkout" alias ga="git add" alias gap="git add --patch" alias gpu="git push" + + +gls() { + zmodload zsh/mapfile + gitignore="$(git rev-parse --show-toplevel 2>/dev/null)/.gitignore" + globalgitignore="$(git config core.excludesfile)" + + typeset -a ignores + for i in $gitignore $globalgitignore; do + if [[ -e $i ]]; then + for ignore in "${(f)mapfile[$i]}"; do + ignores+="--ignore=$ignore" + done + fi + done + + ls --color=auto -h $ignores "$@" +} + +alias gll="gls -l" +alias glll="gls -la" diff --git a/aliases/mpd b/aliases/mpd new file mode 100755 index 0000000..61296ed --- /dev/null +++ b/aliases/mpd @@ -0,0 +1,8 @@ +#!/bin/zsh + +mpc() { + eval $(mpd-host get) + export MPD_HOST + export MPD_PORT + command mpc "$@" +} diff --git a/compdef/_conf b/compdef/_conf new file mode 100644 index 0000000..7aba86b --- /dev/null +++ b/compdef/_conf @@ -0,0 +1,3 @@ +#compdef conf + +_arguments "1:Commands:(${(k)conf_locations})" diff --git a/compdef/_tagsistant-helper b/compdef/_tagsistant-helper new file mode 100644 index 0000000..589e67e --- /dev/null +++ b/compdef/_tagsistant-helper @@ -0,0 +1,33 @@ +#compdef tagsistant-helper tag tcd + +tagdir=${TAGSISTENT_ROOT:-$HOME/tagged}/store + +_file_or_tag() { + _alternative \ + "files:file:_files" \ + "tags:tag:_files -W $tagdir" +} + +_tag() { + typeset -A opt_args + local context state line + + _arguments \ + "*:argument:_file_or_tag" \ + "-n[set target name]:target name:" \ + "--name[set target name]:target name:" \ + "-p[preview]" +} + +_tcd() { + _files -W $tagdir +} + +_tagsistant-helper() { + case $service in + tag) _tag;; + tcd) _tcd;; + papertag) _papertag;; + *) _message "Err";; + esac +} diff --git a/compdef/_xd b/compdef/_xd new file mode 100644 index 0000000..5497bb1 --- /dev/null +++ b/compdef/_xd @@ -0,0 +1,8 @@ +#compdef xd + +function _xd { + typeset -a targets + targets=("${(@f)$(xd -l)}") + _describe target targets +} + diff --git a/modules/bindings/init b/modules/bindings/init index 091f0a8..462a33b 100644 --- a/modules/bindings/init +++ b/modules/bindings/init @@ -59,3 +59,7 @@ function zle-line-finish () { } zle -N zle-line-init zle -N zle-line-finish + +insert_sudo () { zle beginning-of-line; zle -U "sudo " } +zle -N insert-sudo insert_sudo +bindkey "^[s" insert-sudo diff --git a/modules/conf/init b/modules/conf/init new file mode 100755 index 0000000..8b66981 --- /dev/null +++ b/modules/conf/init @@ -0,0 +1,22 @@ +#!/bin/zsh + +conf() { + local target=${conf_locations[${1}]} + if [[ -d ${target} ]]; then + cd ${target} + if ! [[ -w ${target} ]]; then + su + fi + elif [[ -f ${target} ]]; then + if ! [[ -w ${target} ]]; then + sudoedit ${target} + else + $EDITOR ${target} + fi + elif [[ -n ${target} ]]; then + echo "Conf target for $1 missing: $target" + else + echo "Unknown conf target: $1" + fi + +} diff --git a/modules/fuck/init b/modules/fuck/init new file mode 100644 index 0000000..40203d6 --- /dev/null +++ b/modules/fuck/init @@ -0,0 +1,3 @@ +if exists thefuck; then + eval "$(thefuck --alias)" +fi diff --git a/modules/localrc/init b/modules/localrc/init new file mode 100755 index 0000000..b49b068 --- /dev/null +++ b/modules/localrc/init @@ -0,0 +1,10 @@ +#!/bin/zsh + +load_localrc() { + local dir=${1:-$PWD} + if [[ -f $dir/.lzshrc ]]; then source $dir/.lzshrc + elif [[ "$dir" != "/" ]]; then load_localrc ${dir:h} + fi +} + +chpwd_hook load_localrc diff --git a/zshrc b/zshrc index 0300364..838719e 100644 --- a/zshrc +++ b/zshrc @@ -45,4 +45,18 @@ zstyle ':completion:*:messages' format ‘%d’ zstyle ':completion:*:warnings' format ‘No matches for: %d’ +typeset -A conf_locations +conf_locations=( + vim $XDG_CONFIG_HOME/vim + awesome $XDG_CONFIG_HOME/awesome + mutt $HOME/.mutt/muttrc + xd $XDG_CONFIG_HOME/xd.conf + zsh /etc/zsh + offlineimap $XDG_CONFIG_HOME/offlineimap/config + compose $HOME/.XCompose.long + vdirsyncer $HOME/.vdirsyncer/config + xd $XDG_CONFIG_HOME/xd.conf + ssh $HOME/.ssh/config +) + exists todo && todo