config/shell: improve functions slightly
This commit is contained in:
parent
01210a4734
commit
aa464386ad
|
@ -20,6 +20,9 @@ editright() {
|
||||||
(test ! -f "$1" -o -O "$1") && $EDITOR "$1" || sudoedit "$1"
|
(test ! -f "$1" -o -O "$1") && $EDITOR "$1" || sudoedit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Underline arg
|
||||||
|
highlight() { echo "[4m$1[0m" }
|
||||||
|
|
||||||
alias dedup='awk '"'"'!a[$0]++'"'"
|
alias dedup='awk '"'"'!a[$0]++'"'"
|
||||||
edconf() {
|
edconf() {
|
||||||
conf_cache_dir="$XDG_CACHE_HOME/edconf"
|
conf_cache_dir="$XDG_CACHE_HOME/edconf"
|
||||||
|
@ -29,7 +32,7 @@ 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 --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 --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")"
|
||||||
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +51,7 @@ edshell() {
|
||||||
}
|
}
|
||||||
|
|
||||||
edbin() {
|
edbin() {
|
||||||
file="$( (which $1 || echo "$HOME/.local/bin/$1") | tail -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
|
||||||
}
|
}
|
||||||
|
@ -67,7 +70,7 @@ t() {
|
||||||
if test "$#" -eq 0
|
if test "$#" -eq 0
|
||||||
then tn
|
then tn
|
||||||
else if test "$1" = "do"
|
else if test "$1" = "do"
|
||||||
then test "$2" -gt 0 && task mod sched:today "${@:2}" || task add sched:today "${@:2}"
|
then test "$2" -gt 0 2>/dev/null && task mod sched:today "${@:2}" || task add sched:today "${@:2}"
|
||||||
else task "$@"
|
else task "$@"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -23,7 +23,7 @@ listprojects() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Underlines the project names
|
# Underline the project names
|
||||||
highlight() { echo "[4m$1[0m" }
|
highlight() { echo "[4m$1[0m" }
|
||||||
|
|
||||||
# Lists all projects and evaluates the given command.
|
# Lists all projects and evaluates the given command.
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
arg=$(test $# -gt 0 && echo "${@:-1}" || echo .)
|
arg=$(test $# -gt 0 && echo "${@:-1}" || echo .)
|
||||||
file $arg | grep -v --color=never directory
|
file $arg | grep -v --color=never directory
|
||||||
case "$(file --dereference $arg)" in
|
case "$(file --dereference $arg)" in
|
||||||
*directory) ls -l --almost-all --human-readable --group-directories-first --file-type --dereference-command-line "$@";;
|
*directory) ls -l --color=auto --almost-all --human-readable --group-directories-first --file-type --dereference-command-line "$@";;
|
||||||
*text*) bat --style header "$@";;
|
*text*) bat --style header "$@";;
|
||||||
esac
|
esac
|
||||||
#fi
|
#fi
|
||||||
|
|
Loading…
Reference in New Issue