From 85b179e60dda2ba2b7b90bd96d7d7e9ade148612 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 29 May 2021 14:55:41 +0300 Subject: [PATCH 1/3] [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 2/3] [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 3/3] [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 {{{