summaryrefslogtreecommitdiff
path: root/zsh
diff options
context:
space:
mode:
authorSkladnayazebra <skladnayazebra@gmail.com>2025-10-12 15:11:47 +0200
committerSkladnayazebra <skladnayazebra@gmail.com>2025-10-12 15:11:47 +0200
commited47d3f0da1581d3df04d2e506abbbf3686085e9 (patch)
treefe54a12dc573980cfd190f096c58de7908b02015 /zsh
parente207122a6487ea7b8a57b6f065397490cfdfd370 (diff)
zsh config
Diffstat (limited to 'zsh')
-rw-r--r--zsh/keybinds.zsh47
-rw-r--r--zsh/prompt.zsh53
-rw-r--r--zsh/utils.zsh132
3 files changed, 232 insertions, 0 deletions
diff --git a/zsh/keybinds.zsh b/zsh/keybinds.zsh
new file mode 100644
index 0000000..8e27ea9
--- /dev/null
+++ b/zsh/keybinds.zsh
@@ -0,0 +1,47 @@
+# keybinds from arch wiki https://wiki.archlinux.org/title/Zsh
+
+# create a zkbd compatible hash;
+# to add other keys to this hash, see: man 5 terminfo
+typeset -g -A key
+
+key[Home]="${terminfo[khome]}"
+key[End]="${terminfo[kend]}"
+key[Insert]="${terminfo[kich1]}"
+key[Backspace]="${terminfo[kbs]}"
+key[Delete]="${terminfo[kdch1]}"
+key[Up]="${terminfo[kcuu1]}"
+key[Down]="${terminfo[kcud1]}"
+key[Left]="${terminfo[kcub1]}"
+key[Right]="${terminfo[kcuf1]}"
+key[PageUp]="${terminfo[kpp]}"
+key[PageDown]="${terminfo[knp]}"
+key[Shift-Tab]="${terminfo[kcbt]}"
+key[Control-Left]="${terminfo[kLFT5]}"
+key[Control-Right]="${terminfo[kRIT5]}"
+
+# setup key accordingly
+[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
+[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
+[[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode
+[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
+[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
+[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history
+[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history
+[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
+[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
+[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
+[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
+[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
+
+[[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word
+[[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word
+
+# Finally, make sure the terminal is in application mode, when zle is
+# active. Only then are the values from $terminfo valid.
+if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
+ autoload -Uz add-zle-hook-widget
+ function zle_application_mode_start { echoti smkx }
+ function zle_application_mode_stop { echoti rmkx }
+ add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
+ add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
+fi
diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh
new file mode 100644
index 0000000..774f5f0
--- /dev/null
+++ b/zsh/prompt.zsh
@@ -0,0 +1,53 @@
+
+# init prompts
+# my fancy prompt
+autoload -Uz promptinit
+promptinit
+
+autoload -Uz vcs_info
+
+setopt PROMPT_SUBST
+
+GIT_INFO=""
+
+zstyle ':vcs_info:git*' formats "  %b %c%u%m%a"
+zstyle ':vcs_info:*' enable git
+zstyle ':vcs_info:*' check-for-changes true
+zstyle ':vcs_info:*' stagedstr ' %K{green} ✚ %k'
+zstyle ':vcs_info:*' unstagedstr ' %K{red} ● %k'
+
+PS_GIT_TAGS=""
+PS_NODE=""
+
+PS_ERR="%0(?..%K{red}(%?%)%k)";
+PS_GIT='%K{blue}$vcs_info_msg_0_%k'
+PS_USER='%K{blue}[%n@%M] %k'
+PS_DIR='%K{green}  %1~ %k'
+
+
+get_pkg_manager() {
+ if [[ -f yarn.lock ]]; then
+ echo " "
+ elif [[ -f pnpm-lock.yaml ]]; then
+ echo " "
+ elif [[ -f package-lock.json ]]; then
+ echo " "
+ else
+ echo ""
+ fi
+}
+
+precmd() {
+ vcs_info
+
+ PS_NODE="$(get_pkg_manager)"
+ git_tag=$(git describe --tags HEAD 2>/dev/null)
+
+ if [[ $git_tag ]]; then
+ PS_GIT_TAGS="%K{black}  $git_tag %k"
+ else
+ PS_GIT_TAGS=""
+ fi
+
+ PROMPT="%B$PS_ERR$PS_DIR$PS_GIT$PS_GIT_TAGS$PS_NODE %# %b"
+}
diff --git a/zsh/utils.zsh b/zsh/utils.zsh
new file mode 100644
index 0000000..111a2fb
--- /dev/null
+++ b/zsh/utils.zsh
@@ -0,0 +1,132 @@
+deps() {
+ if [[ -f yarn.lock ]]; then
+ yarn list --pattern "@arf/|@arjs/|@dt/|@grapecity/|@mescius/|barcodejs|js-expressions" --depth=0 -s
+ elif [[ -f pnpm-lock.yaml ]]; then
+ pnpm list @arf/* @arjs/* @dt/* @grapecity/* @mescius/* barcodejs js-expressions
+ elif [[ -f package-lock.json ]]; then
+ echo "NPM does not support dependencies filtering, here's the full list:"
+ npm list
+ else
+ echo "No package manager in this directory"
+ return 1
+ fi
+}
+
+# opens PR on bitbucket
+bb() {
+ repoUrl=$(npm repo --browser=false | grep http)
+ branch=$(git rev-parse --abbrev-ref HEAD | jq -sRr @uri)
+ xdg-open "$repoUrl/pull-requests/new?source=$branch"
+}
+
+# git -C $line describe --tags HEAD [latest tag]
+# git -C $line tag --points-at HEAD [latest tagS]
+
+# shows project list
+lsproj() {
+ ls | while read line;
+ do {
+ fill_count=$((32 - ${#line}))
+ filler=$(repeat $fill_count printf "·")
+ is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
+ if [[ $is_git_repo ]] {
+ project_dir="%B%K{green} $line $filler %k%b"
+ branch=" %F{blue} $(git -C $line rev-parse --abbrev-ref HEAD)%f"
+ tag=$(git -C $line describe --tags HEAD 2> /dev/null)
+ print -P "$project_dir$branch [$tag]";
+ }
+ }
+ done
+}
+
+lsproj2() {
+ ls | while read line;
+ do {
+ fill_count=$((32 - ${#line}))
+ filler=$(repeat $fill_count printf "·")
+ is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
+ if [[ $is_git_repo ]] {
+ project_dir="%B%F{white}%K{green} $line %k%f%b"
+ branch=" %F{blue} $(git -C $line rev-parse --abbrev-ref HEAD)%f"
+ # tag=$(git -C $line describe --tags HEAD 2> /dev/null)
+ print -P "|$project_dir\n|$branch\n|"
+ }
+ }
+ done
+}
+
+lsproj_watch() {
+ while true;
+ do {
+ output=$(lsproj)
+ clear;
+ print $output;
+ sleep 1;
+ }
+ done;
+}
+
+# TEMP
+
+chkt() {
+ ls | while read line;
+ do {
+ fill_count=$((32 - ${#line}))
+ filler=$(for i in {1..$fill_count}; do printf "·"; done)
+ is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
+ if [[ $is_git_repo ]] {
+ print "%B%F{white}%K{green} $line %k%f%b"
+ git -C $line branch
+ }
+ }
+ done
+}
+
+fore() {
+ while read proj;
+ do {
+ echo $proj
+ git -C $proj branch -d feature/update-arf-toolkit 2> /dev/null && echo "OK"
+ }
+ done
+}
+
+
+multiupd() {
+ echo $1
+ start_path=$(pwd)
+ while read proj;
+ do {
+ cd $start_path/$proj
+ print -P "%K{green}%F{white}%B update to $1 in $start_path/$proj %b%f%k"
+
+ if [[ -f yarn.lock ]]; then
+ yarn add $1 -E -W 2> >(grep -v warning 1>&2)
+ git add yarn.lock
+ elif [[ -f pnpm-lock.yaml ]]; then
+ pnpm i $1 -E
+ git add pnpm-lock.yaml
+ elif [[ -f package-lock.json ]]; then
+ npm i $1 -E
+ git add package-lock.json
+ fi
+ git add package.json
+ }
+ done
+
+ cd $start_path
+}
+
+createbr() {
+ start_path=$(pwd)
+ while read proj;
+ do {
+ cd $start_path/$proj
+ print -P "%K{green}%F{white}%B $start_path/$proj %b%f%k"
+ git co -b feature/update-arf-toolkit
+ git ci -m "@arf/toolkit 0.16.5"
+ git push
+ bb 2> /dev/null || echo "PR is not open: $proj"
+ }
+ done
+}