config/shell: fix editing aliases
This commit is contained in:
parent
7985f33b53
commit
0184ef2ace
|
@ -18,9 +18,9 @@ alias info='info --vi-keys'
|
||||||
alias editgrub='sudoedit /etc/default/grub && sudo update-grub'
|
alias editgrub='sudoedit /etc/default/grub && sudo update-grub'
|
||||||
alias editenv='sudoedit /etc/environment'
|
alias editenv='sudoedit /etc/environment'
|
||||||
editright() {
|
editright() {
|
||||||
test ! -f "$1" && mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1")
|
test ! -f "$1" && ( mkdir -p $(dirname "$1") || sudo mkdir -p $(dirname "$1") )
|
||||||
echo "Editing $1..."
|
echo "Editing $1..."
|
||||||
(test -O "$1" || (test ! -f "$1" && test -O $(dirname "$1"))) && $EDITOR "$1" || sudoedit "$1"
|
(test -w "$1" || (test ! -f "$1" && test -w $(dirname "$1"))) && $EDITOR "$1" || sudoedit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Underline arg
|
# Underline arg
|
||||||
|
@ -35,7 +35,10 @@ edconf() {
|
||||||
mkdir -p "$conf_cache_dir"
|
mkdir -p "$conf_cache_dir"
|
||||||
touch "$conf_cache"
|
touch "$conf_cache"
|
||||||
# | xargs file | grep text | cut -d':' -f1 # this filters out non-text files, but it's ridiculously slow
|
# | xargs file | grep text | cut -d':' -f1 # this filters out non-text files, but it's ridiculously slow
|
||||||
sel="$({ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra"; fd --type file --size -1m --hidden --exact-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")"
|
sel="$({ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
|
||||||
|
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") & editright "$sel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +46,10 @@ CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
|
||||||
alias r="reset && exec zsh"
|
alias r="reset && exec zsh"
|
||||||
edshell() {
|
edshell() {
|
||||||
case $1 in
|
case $1 in
|
||||||
"") file="$CONFIG_SHELL_FUNCTIONS";;
|
("") file="$CONFIG_SHELL_FUNCTIONS";;
|
||||||
zsh) file="$CONFIG_ZSH/.zshrc";;
|
(zsh) file="$CONFIG_ZSH/.zshrc";;
|
||||||
prof*) file="$HOME/.zprofile";;
|
(prof*) file="$HOME/.zprofile";;
|
||||||
*) file=$(find $CONFIG_SHELLS -name "$1*" | head -1);;
|
(*) file=$(find $CONFIG_SHELLS -name "$1*" | head -1);;
|
||||||
esac
|
esac
|
||||||
checksum="$(md5sum $file)"
|
checksum="$(md5sum $file)"
|
||||||
$EDITOR $file
|
$EDITOR $file
|
||||||
|
@ -56,7 +59,7 @@ edshell() {
|
||||||
edbin() {
|
edbin() {
|
||||||
file="$(f=$(which $1) && test -f "$f" && echo $f || echo "$HOME/.local/bin/$1")"
|
file="$(f=$(which $1) && test -f "$f" && echo $f || echo "$HOME/.local/bin/$1")"
|
||||||
editright "$file"
|
editright "$file"
|
||||||
case "$file" in $HOME) yadm add "$file";; esac
|
case "$file" in ($HOME*) yadm add "$file";; esac
|
||||||
}
|
}
|
||||||
|
|
||||||
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
|
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
|
||||||
|
|
Loading…
Reference in New Issue