From 94c5e661059310ce21b0ff38860c109fd2738617 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Thu, 16 Sep 2021 18:18:10 +0800 Subject: [PATCH] feat: support termux --- cli/fish.sh | 68 +++++++++++++++++++++++--------------------- cli/fish/config.fish | 2 +- cli/tmux.sh | 58 +++++++++++++++++++------------------ cli/tmux/tmux.conf | 2 +- cli/vim.sh | 5 ++-- env.sh | 4 +-- 6 files changed, 72 insertions(+), 67 deletions(-) diff --git a/cli/fish.sh b/cli/fish.sh index a4822e2..12b8268 100755 --- a/cli/fish.sh +++ b/cli/fish.sh @@ -5,40 +5,42 @@ DIR=$(dirname "$(readlink -f "$0")") . "$DIR/../env.sh" log 'Setting up shell' -case "$PM" in - apt) - sudo add-apt-repository ppa:fish-shell/release-3 -y -n - pm_update - sudo apt install fish silversearcher-ag -y - echo DISTRIB_RELEASE_MAJOR: $DISTRIB_RELEASE_MAJOR - echo DISTRIB_RELEASE: $DISTRIB_RELEASE - if [ "$DISTRIB_RELEASE_MAJOR" -gt 19 ] || [ "$DISTRIB_RELEASE" = "19.10" ]; then - sudo apt install dash bat -y - fi - sudo ln -sf /usr/bin/batcat /usr/bin/bat - intorepo https://github.com/junegunn/fzf.git "$HOME/.fzf" - ./install --all - exitrepo - ;; - pacman) - sudo pacman -S --noconfirm --needed fish the_silver_searcher dash bat fzf - # prevent bash upgradation relink /bin/sh - sudo mkdir -p /etc/pacman.d/hooks - echo " - [Trigger] - Type = Package - Operation = Install - Operation = Upgrade - Target = bash +if ! has_cmd fish; then + case "$PM" in + apt) + sudo add-apt-repository ppa:fish-shell/release-3 -y -n + pm_update + sudo apt install fish silversearcher-ag -y + echo DISTRIB_RELEASE_MAJOR: $DISTRIB_RELEASE_MAJOR + echo DISTRIB_RELEASE: $DISTRIB_RELEASE + if [ "$DISTRIB_RELEASE_MAJOR" -gt 19 ] || [ "$DISTRIB_RELEASE" = "19.10" ]; then + sudo apt install dash bat -y + fi + sudo ln -sf /usr/bin/batcat /usr/bin/bat + intorepo https://github.com/junegunn/fzf.git "$HOME/.fzf" + ./install --all + exitrepo + ;; + pacman) + sudo pacman -S --noconfirm --needed fish the_silver_searcher dash bat fzf + # prevent bash upgradation relink /bin/sh + sudo mkdir -p /etc/pacman.d/hooks + echo " + [Trigger] + Type = Package + Operation = Install + Operation = Upgrade + Target = bash - [Action] - Description = Re-pointing /bin/sh symlink to dash... - When = PostTransaction - Exec = /usr/bin/ln -sfT dash /usr/bin/sh - Depends = dash - " | sed 's/^ *//' | sudo tee /etc/pacman.d/sh-is-dash.hook >/dev/null - ;; -esac + [Action] + Description = Re-pointing /bin/sh symlink to dash... + When = PostTransaction + Exec = /usr/bin/ln -sfT dash /usr/bin/sh + Depends = dash + " | sed 's/^ *//' | sudo tee /etc/pacman.d/sh-is-dash.hook >/dev/null + ;; + esac +fi # only for local machine with gui diff --git a/cli/fish/config.fish b/cli/fish/config.fish index 910ac83..51192dd 100644 --- a/cli/fish/config.fish +++ b/cli/fish/config.fish @@ -2,7 +2,7 @@ if status is-interactive # === default programs - set -gx EDITOR v + set -gx EDITOR vim # === fzf configuration set -gx FZF_DEFAULT_COMMAND 'ag -g ""' diff --git a/cli/tmux.sh b/cli/tmux.sh index ad6ef35..fcfb098 100755 --- a/cli/tmux.sh +++ b/cli/tmux.sh @@ -6,35 +6,37 @@ DIR=$(dirname "$(readlink -f "$0")") log 'Setting up tmux' -case "$PM" in - apt) - TMUX_VER=3.2 - if ! has_cmd tmux || [ "$(tmux -V)" != "tmux $TMUX_VER" ]; then - sudo apt install libevent-dev libncurses5-dev bison autoconf bc -y - TMUX_SRC_URL=https://github.com/tmux/tmux/releases/download/$TMUX_VER/tmux-$TMUX_VER.tar.gz - #if in_china; then - #TMUX_SRC_URL="https://gitee.com/klesh/tmux/repository/archive/$TMUX_VER?format=tar.gz" - #fi - if [ ! -f /tmp/tmux.tar.gz ]; then - curl -L "$TMUX_SRC_URL" -o /tmp/tmux.tar.gz +if ! has_cmd tmux; then + case "$PM" in + apt) + TMUX_VER=3.2 + if ! has_cmd tmux || [ "$(tmux -V)" != "tmux $TMUX_VER" ]; then + sudo apt install libevent-dev libncurses5-dev bison autoconf bc -y + TMUX_SRC_URL=https://github.com/tmux/tmux/releases/download/$TMUX_VER/tmux-$TMUX_VER.tar.gz + #if in_china; then + #TMUX_SRC_URL="https://gitee.com/klesh/tmux/repository/archive/$TMUX_VER?format=tar.gz" + #fi + if [ ! -f /tmp/tmux.tar.gz ]; then + curl -L "$TMUX_SRC_URL" -o /tmp/tmux.tar.gz + fi + rm -rf /tmp/tmux + mkdir -p /tmp/tmux + tar zxvf /tmp/tmux.tar.gz -C /tmp/tmux --strip 1 + cd /tmp/tmux + if [ -f autogen.sh ]; then + sh autogen.sh + fi + ./configure && make + sudo make install + cd - + rm -rf /tmp/tmux fi - rm -rf /tmp/tmux - mkdir -p /tmp/tmux - tar zxvf /tmp/tmux.tar.gz -C /tmp/tmux --strip 1 - cd /tmp/tmux - if [ -f autogen.sh ]; then - sh autogen.sh - fi - ./configure && make - sudo make install - cd - - rm -rf /tmp/tmux - fi - ;; - pacman) - sudo pacman -S --noconfirm --needed tmux bc - ;; -esac + ;; + pacman) + sudo pacman -S --noconfirm --needed tmux bc + ;; + esac +fi # symlink configuration lnsf "$DIR/tmux/tmux.conf" "$HOME/.tmux.conf" diff --git a/cli/tmux/tmux.conf b/cli/tmux/tmux.conf index 9e6bf25..1fbcd40 100644 --- a/cli/tmux/tmux.conf +++ b/cli/tmux/tmux.conf @@ -18,7 +18,7 @@ set-option -g set-titles-string "#S / #W" ############################ setw -g mode-keys vi set -g status-keys vi -set -g default-shell /usr/bin/fish +set -g default-shell $SHELL # set -g prefix C-h bind c new-window -c '#{pane_current_path}' bind '"' split-window -c '#{pane_current_path}' diff --git a/cli/vim.sh b/cli/vim.sh index e3b2cee..a38b158 100755 --- a/cli/vim.sh +++ b/cli/vim.sh @@ -16,7 +16,8 @@ if [ "$VIM_MODE" = "enhanced" ]; then fi fi -# install nvim +# install vim +export VIM=vim if ! has_cmd "$VIM"; then case "$PM" in apt) @@ -51,7 +52,7 @@ if ! has_cmd "$VIM"; then fi # symlink configuration -sudo ln -sf "$(command -v vim)" /usr/bin/v +#sudo ln -sf "$(command -v vim)" /usr/bin/v lnsf "$DIR/vim/init.vim" "$XDG_CONFIG_HOME/nvim/init.vim" lnsf "$DIR/vim/coc-settings.json" "$XDG_CONFIG_HOME/nvim/coc-settings.json" lnsf "$DIR/vim/coc-settings.json" "$HOME/.vim/coc-settings.json" diff --git a/env.sh b/env.sh index f474890..5af7c75 100755 --- a/env.sh +++ b/env.sh @@ -30,7 +30,7 @@ lnsf() { } has_bluetooth() { - sudo dmesg | grep -i bluetooth + has_cmd sudo && sudo dmesg | grep -i bluetooth } eqv() { @@ -104,7 +104,7 @@ win_env_path() { } -sudo mkdir -p $PREFIX +has_cmd sudo && sudo mkdir -p $PREFIX if has_cmd pacman; then PM=pacman