config/shell: small fixes

This commit is contained in:
xerus2000 2020-11-22 19:55:59 +01:00
parent ef80431997
commit 2e70dacde5
5 changed files with 24 additions and 20 deletions

View File

@ -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'

View File

@ -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)"

View File

@ -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

View File

@ -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

8
.local/bin/edit Executable file
View File

@ -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