From aa464386ad9842d65e625c32a922eba1395d2a33 Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Fri, 23 Oct 2020 22:17:58 +0200 Subject: [PATCH] config/shell: improve functions slightly --- .config/shell/functions | 9 ++++++--- .config/shell/projects | 2 +- .local/bin/b | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index ccacf59..1e80350 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -20,6 +20,9 @@ editright() { (test ! -f "$1" -o -O "$1") && $EDITOR "$1" || sudoedit "$1" } +# Underline arg +highlight() { echo "$1" } + alias dedup='awk '"'"'!a[$0]++'"'" edconf() { conf_cache_dir="$XDG_CACHE_HOME/edconf" @@ -29,7 +32,7 @@ edconf() { mkdir -p "$conf_cache_dir" touch "$conf_cache" # | 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") } @@ -48,7 +51,7 @@ edshell() { } 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" case "$file" in $HOME) yadm add "$file";; esac } @@ -67,7 +70,7 @@ t() { if test "$#" -eq 0 then tn 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 "$@" fi fi diff --git a/.config/shell/projects b/.config/shell/projects index 1c787f9..442b3d4 100644 --- a/.config/shell/projects +++ b/.config/shell/projects @@ -23,7 +23,7 @@ listprojects() { fi } -# Underlines the project names +# Underline the project names highlight() { echo "$1" } # Lists all projects and evaluates the given command. diff --git a/.local/bin/b b/.local/bin/b index 9c8a168..dd0fd01 100755 --- a/.local/bin/b +++ b/.local/bin/b @@ -11,7 +11,7 @@ arg=$(test $# -gt 0 && echo "${@:-1}" || echo .) file $arg | grep -v --color=never directory 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 "$@";; esac #fi