From 8b10cb3963396ff243880436f6e4b9a07b6400c4 Mon Sep 17 00:00:00 2001 From: tavo Date: Sun, 3 Aug 2025 18:07:37 -0600 Subject: [PATCH] yazi wrapper --- shell/profile.d/android.sh | 16 +++- shell/profile.d/node.sh | 6 ++ shell/profile.d/xdgspec.sh | 8 +- sway/config | 1 + wrappers/yazi | 163 +++++++++++++++++++++++++++++++++++++ 5 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 shell/profile.d/node.sh create mode 100755 wrappers/yazi diff --git a/shell/profile.d/android.sh b/shell/profile.d/android.sh index f945406..ee783c7 100644 --- a/shell/profile.d/android.sh +++ b/shell/profile.d/android.sh @@ -1,8 +1,20 @@ -if [ -f "$XDG_DATA_HOME" ] ; then +if [ -n "$XDG_DATA_HOME" ] ; then + export ANDROID_USER_HOME="$XDG_DATA_HOME"/android export ANDROID_HOME=$XDG_DATA_HOME/Android/Sdk else - export ANDROID_HOME=$HOME/Android/Sdk + export ANDROID_USER_HOME="$HOME"/.local/share/android + export ANDROID_HOME=$HOME/.local/share/Android/Sdk fi +if ! [ -f "$ANDROID_USER_HOME" ] ; then + mkdir -p "$ANDROID_USER_HOME" +fi + +if ! [ -f "$ANDROID_HOME" ] ; then + mkdir -p "$ANDROID_HOME" +fi + +alias adb='HOME="$ANDROID_USER_HOME" adb' + export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/platform-tools diff --git a/shell/profile.d/node.sh b/shell/profile.d/node.sh new file mode 100644 index 0000000..2eb9f79 --- /dev/null +++ b/shell/profile.d/node.sh @@ -0,0 +1,6 @@ +export NODE_REPL_HISTORY="$HOME"/.local/state/node_repl_history + +if ! [ -d "${NODE_REPL_HISTORY%/*}" ] ; then + mkdir -p "${NODE_REPL_HISTORY%/*}" + touch "$NODE_REPL_HISTORY" +fi diff --git a/shell/profile.d/xdgspec.sh b/shell/profile.d/xdgspec.sh index 0b3f159..52a05fa 100644 --- a/shell/profile.d/xdgspec.sh +++ b/shell/profile.d/xdgspec.sh @@ -28,6 +28,10 @@ export \ SSH_CONFIG="-F ${XDG_CONFIG_HOME}/ssh/config" \ GIT_SSH_COMMAND="ssh -F ${XDG_CONFIG_HOME}/ssh/config" \ ZDOTDIR="$XDG_CONFIG_HOME/shell" \ - NPM_CONFIG_USERCONFIG=$XDG_CONFIG_HOME/npm/npmrc \ + NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc" \ IPYTHONDIR="$XDG_CONFIG_HOME/ipython" \ - PYENV_ROOT="$XDG_DATA_HOME"/pyenv + PYENV_ROOT="$XDG_DATA_HOME/pyenv" \ + PYTHON_HISTORY="$XDG_CACHE_HOME/python_history" \ + SQLITE_HISTORY="$XDG_CACHE_HOME/sqlite_history" \ + PGPASSFILE="$XDG_CONFIG_HOME/pg/pgpass" \ + XDG_DATA_DIRS="$XDG_DATA_HOME/flatpak/exports/share${XDG_DATA_DIRS:+:${XDG_DATA_DIRS}}" diff --git a/sway/config b/sway/config index 44a2e0c..988ed88 100644 --- a/sway/config +++ b/sway/config @@ -107,6 +107,7 @@ bindsym $mod+f fullscreen bindsym $mod+Shift+f floating toggle # - bindsym $mod+Shift+c exec clipman pick -t wofi -T'--show dmenu -I' +bindsym $mod+n split horizontal; layout tabbed # Layout client.focused $col_fg $col_fg $col_bg $col_fg $col_fg diff --git a/wrappers/yazi b/wrappers/yazi new file mode 100755 index 0000000..b155456 --- /dev/null +++ b/wrappers/yazi @@ -0,0 +1,163 @@ +#!/bin/sh +YAZI_GITHUB="https://github.com/sxyazi/yazi" +YAZI_DIR="${YAZI_DIR:=$HOME/.local/share/yazi}" + +_prompt() { + printf "[YAZI MANAGER] \033[34m%s\033[0m \033[1m[y/n]:\033[0m " "$1" + read -r opt + + case "$opt" in + [Yy]) return 0;; + [Nn]) return 1;; + *) return 1;; + esac +} + +_msg() { + printf "[YAZI MANAGER] \033[0m%s\033[0m\n" "$1" +} + +_error() { + printf "[YAZI MANAGER] \033[31merror: %s\033[0m\n" "$1" +} + +# Cleans $YAZI_DIR +_clean_yazi_versions() { + if [ -d "$YAZI_DIR" ]; then + rm -rf "$YAZI_DIR"/* + fi +} + +# Check if $YAZI_DIR exists, if it doesn't, create it. +# If there is an error, return 1. +_yazi_dir_check() { + if ! [ -d "$YAZI_DIR" ]; then + _prompt "Installation directory '$YAZI_DIR' does not exist, create?" + if [ "$?" -eq 1 ]; then + return 1 + fi + mkdir -p "$YAZI_DIR" + fi +} + +# Echoes list of yazi versions. +_list_yazi_versions() { + for v in "$YAZI_DIR"/*; do + if [ -d "$v" ]; then + echo "${v##*yazi-}" + fi + done +} + +# Echoes latest installed yazi version. e.g. 25.5.31 +# If there is an error, return 1. +_latest_local() { + versions="$(_list_yazi_versions)" + for v in $versions ; do + latest_local="$v" + done + + echo "$latest_local" +} + +# Get the latest installed yazi binary path. +# If there is a problem with the binary, return 1. +_yazi_bin() { + latest_local="$(_latest_local)" + bin="$YAZI_DIR/yazi-$latest_local/yazi-x86_64-unknown-linux-gnu/yazi" + + if [ -x "$bin" ]; then + echo "$bin" + else + return 1 + fi +} + +# Echoes the latest remote available yazi version. e.g. 25.5.31 +# If there is an error, return 1. +_latest_remote() { + release_url="$(curl -Ls -o /dev/null -w %{url_effective} "$YAZI_GITHUB"/releases/latest)" + if [ "$?" -eq 1 ]; then + return 1 + fi + echo "${release_url##*/v}" +} + +# Downloads a given yazi version. e.g. _download_yazi 25.5.31 +# If there is an error, return 1. +_download_yazi() { + version="$1" + target="$YAZI_DIR/yazi-$version.zip" + download_url="$YAZI_GITHUB/releases/download/v$version/yazi-x86_64-unknown-linux-gnu.zip" + + if [ -z "$version" ]; then + _error "provide a version to download. e.g. 25.5.31" + return 1 + fi + + curl -sLo "$target" "$download_url" + if [ "$?" -eq 1 ]; then + _error "failed to download" + return 1 + fi + + if ! [ -f "$target" ]; then + _error "failed to download" + return 1 + fi + + unzip -o "$target" -d "${target%.zip}" >/dev/null + if [ "$?" -eq 1 ]; then + _error "failed to extract" + return 1 + fi + + rm -f "$target" +} + +_update_yazi() { + latest_remote="$(_latest_remote)" + if [ "$?" -eq 1 ]; then + _error "failed to look up latest version" + return 1 + fi + + latest_local="$(_latest_local)" + if [ "$?" -eq 1 ]; then + _error "failed to look up local version" + return 1 + fi + + if [ "$latest_local" != "$latest_remote" ]; then + _msg "installing yazi ${latest_local:-none} -> $latest_remote..." + _download_yazi "$latest_remote" + if [ "$?" -eq 1 ]; then + _error "failed installation" + return 1 + fi + else + _msg "already up-to-date" + fi +} + +YAZI_BIN="$(_yazi_bin)" + +if [ -x "$YAZI_BIN" ]; then + # shellcheck disable=SC2068 + case "$1" in + --manager-update) _update_yazi ;; + --manager-download) _download_yazi $2 ;; + --manager-list) _list_yazi_versions $2 ;; + --manager-clean) _clean_yazi_versions ;; + *) $YAZI_BIN $@ ;; + esac +else + _yazi_dir_check + + _prompt "yazi not installed, download?" + if [ "$?" -eq 1 ]; then + return 1 + fi + + _update_yazi +fi