From 7b7b1ba1c28fa8ecbb5630a89e27f912c9fae142 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Thu, 27 May 2021 12:48:45 +0300 Subject: [PATCH 1/5] [zsh] unify the fzf window settings a little bit --- script-resources/common_script_utils.py | 2 +- scripts/fzf-search-manpage | 2 +- zsh/env.zsh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/script-resources/common_script_utils.py b/script-resources/common_script_utils.py index 239eb11..4d13e50 100644 --- a/script-resources/common_script_utils.py +++ b/script-resources/common_script_utils.py @@ -19,7 +19,7 @@ def run_chooser(choices: Iterable[str], prompt: str = None, async_read: bool = F process_args = [ "fzf", "--with-nth=2..", - "--height=50%", + "--height=40%", "--reverse", "--tiebreak=index", ] diff --git a/scripts/fzf-search-manpage b/scripts/fzf-search-manpage index 1199656..c567225 100755 --- a/scripts/fzf-search-manpage +++ b/scripts/fzf-search-manpage @@ -1,4 +1,4 @@ #!/usr/bin/env sh set -eu # https://superuser.com/a/207474 -apropos . | fzf --no-multi --tiebreak=begin --query="$*" | sed -n 's/^\([^ ]\+\) \?(\([^)]\+\)).*$/\2 \1/p' +apropos . | fzf --height=40% --reverse --no-multi --tiebreak=begin --query="$*" | sed -n 's/^\([^ ]\+\) \?(\([^)]\+\)).*$/\2 \1/p' diff --git a/zsh/env.zsh b/zsh/env.zsh index baf1882..34e23a0 100644 --- a/zsh/env.zsh +++ b/zsh/env.zsh @@ -33,4 +33,4 @@ unset jq_colors export HOMEBREW_NO_AUTO_UPDATE=1 # https://github.com/junegunn/fzf/blob/764316a53d0eb60b315f0bbcd513de58ed57a876/src/tui/tui.go#L496-L515 -export FZF_DEFAULT_OPTS="--color=16" +export FZF_DEFAULT_OPTS="--color=16 --height=40% --reverse" From 3b6fe44f196492a662bf750347d8b9966dc5340d Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 28 May 2021 13:13:21 +0300 Subject: [PATCH 2/5] Revert "fixup! [zsh] add a couple of aliases to numfmt" This reverts commit cbaeeb2f131d9734ec6d8f745a2cca40d5dcec72. --- zsh/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index c5b7eaa..3bc4d0f 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -2,7 +2,7 @@ count() { print -r -- "$#"; } -bytecount() { wc -c "$@" | bytefmt2; } +bytecount() { wc -c "$@" | numfmt --to=iec-i --suffix=B; } mkcd() { mkdir -p "$@" && cd "${@[-1]}"; } From 85b179e60dda2ba2b7b90bd96d7d7e9ade148612 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 29 May 2021 14:55:41 +0300 Subject: [PATCH 3/5] [zsh] open new shells in the last working directory --- zsh/functions.zsh | 23 +++++++++++++++++++++++ zsh/zshrc | 15 ++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 3bc4d0f..9448bea 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -102,3 +102,26 @@ sudoedit() { } alias sudoe="sudoedit" alias sue="sudoedit" + +# This idea was taken from +SYNC_WORKING_DIR_STORAGE="${ZSH_CACHE_DIR}/last-working-dir" + +autoload -Uz add-zsh-hook +add-zsh-hook chpwd sync_working_dir_chpwd_hook +sync_working_dir_chpwd_hook() { + if [[ "$ZSH_SUBSHELL" == 0 ]]; then + sync_working_dir_save + fi +} + +sync_working_dir_save() { + pwd >| "$SYNC_WORKING_DIR_STORAGE" +} + +sync_working_dir_load() { + local dir + if dir="$(<"$SYNC_WORKING_DIR_STORAGE")" 2>/dev/null && [[ -n "$dir" ]]; then + cd -- "$dir" + fi +} +alias cds="sync_working_dir_load" diff --git a/zsh/zshrc b/zsh/zshrc index 8fcf10a..e8bf236 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -23,14 +23,17 @@ autoload -U colors && colors } _perf_timer_stop() { + # Record the stop time as precisely as possible even in the case of an error + local stop_time="$EPOCHREALTIME" local name="$1" if [[ -z "$name" ]]; then print >&2 "$0: usage: $0 " return 1 fi - local stop_time="$EPOCHREALTIME" start_time="${_perf_timers[$name]}" + local start_time="${_perf_timers[$name]}" + unset "_perf_timers[${(qq)name}]" local -i duration="$(( (stop_time - start_time) * 1000 ))" - print -- "$(print -P '%F{8}==>%f') ${name}: ${duration}ms" + print -r -- "$(print -P '%F{8}==>%f') ${name}: ${duration}ms" } # }}} @@ -58,4 +61,10 @@ done _perf_timer_stop "total" -welcome +if [[ -z "$DOTFILES_DISABLE_WELCOME" ]]; then + welcome +fi + +if [[ -z "$DOTFILES_SYNC_LAST_WORKING_DIR" ]]; then + sync_working_dir_load +fi From 0832e579f8da1dfef5ad9a0907dbdf2d6f679856 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 29 May 2021 18:52:40 +0300 Subject: [PATCH 4/5] [scripts/discord-whois] add an option for printing the raw response --- scripts/discord-whois | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/discord-whois b/scripts/discord-whois index 0598fed..41403ee 100755 --- a/scripts/discord-whois +++ b/scripts/discord-whois @@ -12,7 +12,6 @@ import colorama import time import argparse import json -import typing DISCORD_EPOCH = 1420070400000 # milliseconds @@ -38,6 +37,7 @@ parser.add_argument("user_snowflake", type=int) parser.add_argument("--bot-token", type=str) parser.add_argument("--image-size", type=int) parser.add_argument("--get-prop", type=str) +parser.add_argument("--api-response", action='store_true') cli_args = parser.parse_args() user_snowflake = cli_args.user_snowflake @@ -68,6 +68,11 @@ except urllib.error.HTTPError as err: print(err.read(), file=sys.stderr) raise err +if cli_args.api_response: + json.dump(raw_data, sys.stdout, ensure_ascii=False, indent=2) + sys.stdout.write('\n') + sys.exit() + data = {} data["ID"] = raw_data["id"] From 55cfc1862127171e6902eb70e7b3a503e0e8af62 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 29 May 2021 19:30:15 +0300 Subject: [PATCH 5/5] [nvim] a few changes to the colors of the checkhealth menu --- nvim/colors/dotfiles.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nvim/colors/dotfiles.vim b/nvim/colors/dotfiles.vim index bea107b..157fb63 100644 --- a/nvim/colors/dotfiles.vim +++ b/nvim/colors/dotfiles.vim @@ -160,6 +160,11 @@ hi! link SneakScope Visual hi! link SneakLabel Sneak + " checkhealth UI + call s:hi('healthSuccess', 'bg', 0xB, 'bold', '') + call s:hi('healthWarning', 'bg', 0xA, 'bold', '') + call s:hi('healthError', 'bg', 0x8, 'bold', '') + " }}} " AWK {{{