From 2e70dacde54a76b82f0d112e46d3f3fe00f37293 Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Sun, 22 Nov 2020 19:55:59 +0100 Subject: [PATCH] config/shell: small fixes --- .config/shell/functions | 14 +++----------- .config/shell/git | 11 +++++++---- .config/zsh/.zshrc | 9 +++++---- .local/bin/b | 2 +- .local/bin/edit | 8 ++++++++ 5 files changed, 24 insertions(+), 20 deletions(-) create mode 100755 .local/bin/edit diff --git a/.config/shell/functions b/.config/shell/functions index ab005c8..ef38322 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -24,14 +24,6 @@ alias logoff="loginctl terminate-user $USER" # Some aliases alias editgrub='sudoedit /etc/default/grub && sudo update-grub' alias editenv='sudoedit /etc/environment' -editright() { - test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") ) - echo "Editing $1..." - if test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1")) - then $EDITOR "$1" - else sudoedit "$1" - fi -} # Underline arg highlight() { echo "$1" } @@ -49,7 +41,7 @@ edconf() { fd --hidden --type file --size -1m --max-depth 1 . ~; fd --hidden --type file --size -1m --max-depth 3 . --full-path "$XDG_CONFIG_HOME" /etc } | dedup | fzf -1 -0 --tiebreak=end,length --preview 'bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches")" - test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -30 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & editright "$sel") + test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -30 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel") } CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}" @@ -68,7 +60,7 @@ edshell() { edbin() { file="$(f=$(which $1) && test -f "$f" && echo $f || echo "$HOME/.local/bin/$1")" - editright "$file" + edit "$file" case "$file" in ($HOME*) yadm add "$file";; esac } @@ -98,7 +90,7 @@ alias twtest='( TIMEWARRIORDB=/tmp/timewarriordb && mv ${TIMEWARRIORDB} /tmp/twd # Quick shortcuts alias c='clear' -alias v='editright' +alias v='edit' alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' alias lar='last | tac' diff --git a/.config/shell/git b/.config/shell/git index cf5f3a9..ebb927a 100644 --- a/.config/shell/git +++ b/.config/shell/git @@ -81,8 +81,8 @@ gitclone() { gitfork() { builtin cd "$projects_dir/_forks" - gitclone hub "$1" "" "$3" --recurse-submodules - test "$2" && git remote add upstream "$(gitremote github "$1" "$2")" + gitclone github.com "$1" "" "$3" --recurse-submodules + test "$2" && git remote add upstream "$(gitremote github.com "$1" "$2")" git remote -v } @@ -100,8 +100,11 @@ gitorigin() { # set repo as upstream or add a new remote gitupstream() { if test "$2" - then local name="$2"; git remote remove "$2" >/dev/null - else git remote get-url upstream &>/dev/null && local name="$1" || local name="upstream" + then + local name="$2" + git remote remove "$2" 2>/dev/null + else + git remote get-url upstream 2>/dev/null && local name="$1" || local name="upstream" fi local origin="$(git remote get-url origin)" git remote add -f $name "$(echo $origin | cut -d':' -f1):$1/$(echo $origin | cut -d'/' -f2)" diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index c579381..094104a 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -163,12 +163,11 @@ alias zcp='noglob zmv -C' alias zln='noglob zmv -L' alias zsy='noglob zmv -Ls' -for file in $CONFIG_SHELLS/*; do source $file; done - -# Preferred editor which nvim >/dev/null && export EDITOR='nvim' || export EDITOR='vim' -# AUTOMATICALLY ADDED SHIT +for file in $CONFIG_SHELLS/*; do source $file; done + +# GENERATED SHIT export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm @@ -179,6 +178,8 @@ test -s $CONFIG_ZSH/.p10k.zsh && source $CONFIG_ZSH/.p10k.zsh test -d /usr/share/fzf && source /usr/share/fzf/key-bindings.zsh && source /usr/share/fzf/completion.zsh +test -f $XDG_CONFIG_HOME/broot/launcher/bash/br && source $XDG_CONFIG_HOME/broot/launcher/bash/br + which direnv >/dev/null && eval "$(direnv hook zsh)" return 0 diff --git a/.local/bin/b b/.local/bin/b index 8c1fd6d..914686f 100755 --- a/.local/bin/b +++ b/.local/bin/b @@ -6,5 +6,5 @@ file "$last" | grep -v --color=never directory case "$(file --dereference --mime "$last")" in *inode/directory*) ls -l --color=auto --human-readable --group-directories-first --file-type --dereference-command-line --all --reverse "$@";; *binary) ;; - *) bat --style header "$@";; + *) $(test -r "$last" && echo "bat" || echo "sudo bat") --style header "$@";; esac diff --git a/.local/bin/edit b/.local/bin/edit new file mode 100755 index 0000000..f27aa2c --- /dev/null +++ b/.local/bin/edit @@ -0,0 +1,8 @@ +#!/bin/sh + +test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") ) +echo "Editing $1..." +if test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1")) +then $EDITOR "$1" +else sudoedit "$1" +fi