From b7cdbec0203094e39adf0225808a5b5a0a5ec45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Sun, 29 Sep 2024 19:23:01 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(bin):=20use=20the?= =?UTF-8?q?=20global=20editor=20variable=20for=20more=20modularity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/fish/functions/cdzc.fish | 10 ---------- .config/yazi/yazi.toml | 1 + .local/bin/dev | 27 ++++++++++++++++++++------- 3 files changed, 21 insertions(+), 17 deletions(-) delete mode 100644 .config/fish/functions/cdzc.fish diff --git a/.config/fish/functions/cdzc.fish b/.config/fish/functions/cdzc.fish deleted file mode 100644 index 2a30f784..00000000 --- a/.config/fish/functions/cdzc.fish +++ /dev/null @@ -1,10 +0,0 @@ -function cdzc --description 'Open directories from zoxide in vscode' - set selected_dir (zi) - - if test -n "$selected_dir" - cd "$selected_dir" - codium -r . - else - commandline -f repaint - end -end diff --git a/.config/yazi/yazi.toml b/.config/yazi/yazi.toml index 1b9c651a..cf066f2a 100644 --- a/.config/yazi/yazi.toml +++ b/.config/yazi/yazi.toml @@ -17,6 +17,7 @@ folder = [ ] text = [ + { run = '$EDITOR "$@"', block = true, desc = "$EDITOR", for = "linux" }, { run = 'nvim "$@"', block = true, desc = "neovim", for = "linux" }, { run = 'kitty --detach nvim "$@"', block = true, desc = "neovim (detached)", for = "linux" }, { run = 'codium "$@"', orphan = true, desc = "vscodium", for = "linux" }, diff --git a/.local/bin/dev b/.local/bin/dev index 8b9357bb..3a9a2f70 100755 --- a/.local/bin/dev +++ b/.local/bin/dev @@ -59,6 +59,14 @@ handle_kitty() { $eza } +handle_editor() { + if [[ "$EDITOR" == "nvim" || "$EDITOR" == "vim" ]]; then + echo "terminal" + elif [[ "$EDITOR" == "code" || "$EDITOR" == "codium" ]]; then + echo "gui" + fi +} + selected_dir=$($projects_command | $fzf_command --prompt='Select a directory: ' \ --header='CTRL-P: Projects / CTRL-Z: Zoxide' \ --bind "ctrl-p:reload($projects_command)" \ @@ -68,13 +76,18 @@ selected_dir=$($projects_command | $fzf_command --prompt='Select a directory: ' tab_title=$(basename "$selected_dir") if [[ -n "$selected_dir" ]]; then - if command -v tmux &>/dev/null; then - if command -v tmuxp &>/dev/null; then - handle_tmuxp - else - handle_tmux + editor_type=$(handle_editor) + if [[ $editor_type == "terminal" ]]; then + if command -v tmux &>/dev/null; then + if command -v tmuxp &>/dev/null; then + handle_tmuxp + else + handle_tmux + fi + elif [[ "$TERM" == "xterm-kitty" ]]; then + handle_kitty fi - elif [[ "$TERM" == "xterm-kitty" ]]; then - handle_kitty + else + $EDITOR -r "$selected_dir" fi fi