From 97c0cd8882e1182693386514e8a4bcff82b0a3b3 Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sat, 26 Mar 2022 17:39:31 +0900 Subject: [PATCH 1/6] :sparkles: add fish shell --- src/shell.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index 00ad693..1a00bf7 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -9,18 +9,21 @@ use thiserror::Error; pub enum Shell { Bash, Zsh, + Fish, } pub const fn available_shells() -> &'static [&'static str] { - &["bash", "zsh"] + &["bash", "zsh", "fish"] } #[derive(Debug, Error)] pub enum ShellDetectError { #[error("parent process tracing count reached the limit: {MAX_SEARCH_ITERATIONS}")] TooManyTracing, + #[error("reached first process PID=0 when tracing processes")] ReachedFirstProcess, + #[error(transparent)] FailedGetProcessInfo(#[from] ProcessInfoError), } @@ -60,6 +63,7 @@ impl Shell { Bash | Zsh => { format!("export PATH={}:$PATH", path.as_ref().display()) } + Fish => format!("set -gx PATH {} $PATH;", path.as_ref().display()), } } pub fn set_env(&self, name: impl Display, value: impl Display) -> String { @@ -67,6 +71,7 @@ impl Shell { Bash | Zsh => { format!("export {}={}", name, value) } + Fish => format!("set -gx {} {};", name, value), } } pub fn auto_switch_hook(&self, version_file: &version::File) -> String { @@ -83,7 +88,8 @@ impl Shell { match &self { Bash => { - formatdoc! {r#" + formatdoc! { + r#" __phpup_use() {{ {phpup_use} }} @@ -97,7 +103,8 @@ impl Shell { } } Zsh => { - formatdoc! {r#" + formatdoc! { + r#" autoload -U add-zsh-hook _phpup_autoload_hook () {{ {phpup_use} @@ -107,11 +114,22 @@ impl Shell { phpup_use = phpup_use } } + Fish => { + formatdoc!( + r#" + function _phpup_autoload_hook --on-variable PWD --description 'Change PHP version on directory change' + status --is-command-substitution; and return + {phpup_use} + end + _phpup_autoload_hook"#, + phpup_use = phpup_use + ) + } } } pub fn rehash(&self) -> Option { match &self { - Bash => None, + Bash | Fish => None, Zsh => Some("rehash".to_string()), } } @@ -119,6 +137,7 @@ impl Shell { match &self { Bash => clap_complete::Shell::Bash, Zsh => clap_complete::Shell::Zsh, + Fish => clap_complete::Shell::Fish, } } } @@ -135,6 +154,7 @@ impl FromStr for Shell { match s { "bash" | "dash" => Ok(Bash), "zsh" => Ok(Zsh), + "fish" => Ok(Fish), _ => Err(ParseShellError::UnknownShell(s.to_owned())), } } From e6a4825f5fe4e9add1e8977b879d4fe769f3b684 Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sat, 26 Mar 2022 22:48:50 +0900 Subject: [PATCH 2/6] :memo: update README for fish support --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd00414..37cf719 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## Quick Start (Linux, macOS) -For bash, zsh, there's a [installation script](./.ci/install.sh) +For `bash`, `zsh` and `fish` there's a [installation script](./.ci/install.sh) ```sh curl -fsSL https://phpup.vercel.app/install | bash @@ -25,7 +25,7 @@ curl -fsSL https://phpup.vercel.app/install | bash To prevent duplication in your shell config file, add `--skip-shell` option to install command. ```sh -curl -fsSL https://phpup.vercel.app/install | bash -s -- --skip-shell +curl -fsSL https://phpup.vercel.app/install | bash -s -- --skip-shell ``` #### Uninstall @@ -38,8 +38,8 @@ You should also edit your shell configuration to remove any references to phpup. ### Requirements - OS: Linux, macOS, Windows[WIP] -- shell: bash, zsh, fish[WIP], powershell[WIP] -- `curl`/`ps` installation +- shell: `bash`, `zsh`, `fish` or `powershell`[WIP] +- `curl`, `ps` and `make` installation ### Installation @@ -56,11 +56,20 @@ cargo install phpup ### Shell setup +#### Bash, Zsh + Add the following to your `.bashrc` or `.zshrc` -```bash +```sh eval "$(phpup init --auto --recursive)" ``` +#### Fish + +Create `~/.config/fish/conf.d/phpup.fish` and add the following to it + +```fish +phpup init --auto --recursive | source +``` - To automatically run `phpup use` when a directory contains a `.php-version` file, add the `--auto` (long: `--auto-switch`) option. - To search recursively for a `.php-version` file in a parent directory when running `phpup use` automatically, add the `--recursive` (long: `--recursive-version-file`) option. From 91edec3bb206b42a22147ff3b5caa75c7ad12d2d Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sat, 26 Mar 2022 23:58:07 +0900 Subject: [PATCH 3/6] :green_heart: make release contain fish completion --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6f430d..def3240 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -141,6 +141,7 @@ jobs: mkdir -p completions/{bash,zsh} ./target/${{ matrix.target }}/release/phpup completions --shell bash > completions/bash/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell zsh > completions/zsh/_phpup + ./target/${{ matrix.target }}/release/phpup completions --shell fish > completions/fish/phpup.fish - name: Generate completion files (arm) if: matrix.arch == 'armv7' || matrix.arch == 'aarch64' @@ -156,6 +157,7 @@ jobs: mkdir -p completions/{bash,zsh} ./target/${{ matrix.target }}/release/phpup completions --shell bash > completions/bash/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell zsh > completions/zsh/_phpup + ./target/${{ matrix.target }}/release/phpup completions --shell fish > completions/fish/phpup.fish - name: Build archive shell: bash From 506b5e3e2f46d58ba13164275527e682c40a61f4 Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sun, 27 Mar 2022 00:07:36 +0900 Subject: [PATCH 4/6] :spakrles: fix install script for supporing fish --- .ci/install.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.ci/install.sh b/.ci/install.sh index cef85fa..49bf25e 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -169,18 +169,20 @@ setup_shell() { echo '# To use completion, run `compinit` after adding $fpath' >>$CONF_FILE echo '# compinit' >>$CONF_FILE - # elif [ "$CURRENT_SHELL" = "fish" ]; then - # CONF_FILE=$HOME/.config/fish/conf.d/phpup.fish - # ensure_containing_dir_exists "$CONF_FILE" - # echo "Installing for Fish. Appending the following to $CONF_FILE:" - # echo "" - # echo ' # PHP-UP' - # echo ' set PATH '"$INSTALL_DIR"' $PATH' - # echo ' phpup init --auto --recursive | source' - - # echo '# PHP-UP' >>$CONF_FILE - # echo 'set PATH '"$INSTALL_DIR"' $PATH' >>$CONF_FILE - # echo 'phpup init --auto --recursive | source' >>$CONF_FILE + elif [ "$CURRENT_SHELL" = "fish" ]; then + CONF_FILE=$HOME/.config/fish/conf.d/phpup.fish + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Fish. Appending the following to $CONF_FILE:" + echo "" + echo ' # PHP-UP' + echo ' set PATH '$INSTALL_DIR/bin' $PATH' + echo ' phpup init --auto --recursive | source' + echo ' set -gx fish_complete_path '$INSTALL_DIR/completions/fish' $fish_complete_path' + + echo '# PHP-UP' >>$CONF_FILE + echo 'set PATH '$INSTALL_DIR/bin' $PATH' >>$CONF_FILE + echo 'phpup init --auto --recursive | source' >>$CONF_FILE + echo 'set -gx fish_complete_path '$INSTALL_DIR/completions/fish' $fish_complete_path' >>$CONF_FILE elif [ "$CURRENT_SHELL" = "bash" ]; then if [ "$OS" = "Darwin" ]; then From e98c7830862dc86ac1d43dc3c2566a1e0f792ca2 Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sun, 27 Mar 2022 01:11:28 +0900 Subject: [PATCH 5/6] :memo: check TODO --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 9839fac..8dfd975 100644 --- a/TODO.md +++ b/TODO.md @@ -34,7 +34,7 @@ ## Cross-platform support - [x] bash -- [ ] fish +- [x] fish - [ ] windows ## Test From 2be2877df5782a713390257f79eb3451d877068e Mon Sep 17 00:00:00 2001 From: masan4444 Date: Sun, 27 Mar 2022 01:14:04 +0900 Subject: [PATCH 6/6] :bug: fix github actions --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index def3240..ac4b6a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -138,7 +138,7 @@ jobs: - name: Generate completion files (x86_64) if: matrix.arch == 'x86_64' run: | - mkdir -p completions/{bash,zsh} + mkdir -p completions/{bash,zsh,fish} ./target/${{ matrix.target }}/release/phpup completions --shell bash > completions/bash/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell zsh > completions/zsh/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell fish > completions/fish/phpup.fish @@ -154,7 +154,7 @@ jobs: -v $PWD/target:/target:Z \ -v $PWD/completions:/completions:Z run: | - mkdir -p completions/{bash,zsh} + mkdir -p completions/{bash,zsh,fish} ./target/${{ matrix.target }}/release/phpup completions --shell bash > completions/bash/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell zsh > completions/zsh/_phpup ./target/${{ matrix.target }}/release/phpup completions --shell fish > completions/fish/phpup.fish