From: AJ ONeal Date: Tue, 22 Sep 2020 22:51:27 +0000 (+0000) Subject: add fish X-Git-Url: https://git.josue.xyz/?p=webi-installers%2F.git;a=commitdiff_plain;h=b60b4619ba78ef0d0f0470b9ef1405552e73e996 add fish --- diff --git a/fish/README.md b/fish/README.md new file mode 100644 index 0000000..146bac8 --- /dev/null +++ b/fish/README.md @@ -0,0 +1,224 @@ +--- +title: fish +homepage: https://github.com/fish-shell/fish-shell +tagline: | + fish is a smart and user-friendly command line shell for Linux, macOS, and the rest of the family. +--- + +### Updating `fish` + +`webi fish@stable` + +Use the `@beta` tag for pre-releases. + +## Cheat Sheet + +> Finally, a command line shell for the 90s! +> +> fish includes features like syntax highlighting, autosuggest-as-you-type, and +> fancy tab completions that just work, with no configuration required. + +!["fish features"](https://i.imgur.com/WVCyf5N.png) + +`fish` is an _excellent_ command line shell for day-to-day file browsing and +running commands (the _BEST_, in fact). + +However, it is **NOT** compatible with `bash` so you should still write and run +your scripts with bash. + +This also covers how to + +- Run bash scripts with bash +- Set vim to keep using bash +- Set fish as the default shell in **Linux** +- Set fish as the default shell in various Terminals + - Terminal.app + - iTerm2 + - Hyper + - Alacritty +- Find fish's config files +- Set the default shell back to `bash` + +### How to run bash scripts from fish + +A bash script should have a "bash shebang" (`#!/bin/bash`) as the first line of +the file: + +```bash +#!/bin/bash + +echo "Who am I? I'm $(whoami)." +``` + +You can also run bash explicitly: + +```bash +bash ./some-script.sh +``` + +### How to set vim to keep using bash + +The first line of your `.vimrc` should always be `set shell=/bin/bash`. + +`~/.vimrc`: + +```vim +set shell=/bin/bash +``` + +### How to make fish the default shell on Linux + +This requires editing a protected system file, `/etc/shells`. It is better to +use the Terminal-specific methods. + +First, `fish` must be installed and in the `PATH`. + +```bash +# if you don't see a file path as output, fish is not in the path +which fish +``` + +Second, fish must be in the system-approved list of shells in `/etc/shells`: + +```bash +#!/bin/bash + +if ! grep $(which fish) /etc/shells > /dev/null; then + sudo bash -c "echo '$(which fish)' >> /etc/shells"; + echo "added '$(which fish)' to /etc/shells" +fi +``` + +You should use `chsh` to change your shell: + +```bash +#!/bin/bash + +sudo chsh -s "$(which fish)" "$(whoami)" +``` + +If vim uses `fish` instead of `bash`, annoying errors will happen. + +### How to switch to fish + +You can simply type `fish` and hit enter to start using fish from any other +shell. + +You can also set is as the default for a particular Terminal, or for your user. + +### How to set fish as the Terminal.app shell + +Find out where `fish` is: + +```bash +which fish +``` + +Then update the Terminal preferences: + +```txt +Terminal > Preferences > General > Shells open with: +/Users/YOUR_USER/.local/bin/fish +``` + +![Terminal.app preferences](https://i.imgur.com/bulS4Vv.png) + +Or, you can quit Terminal and change the preferences from the command line: + +```bash +#!/bin/bash + +defaults write com.apple.Terminal "Shell" -string "$HOME/.local/bin/fish" +``` + +### How to set fish as the iTerm2 shell + +Find out where `fish` is: + +```bash +which fish +``` + +Then update iTerm2 preferences: + +``` +iTerm2 > Preferences > Profiles > General > Command > +Custom Shell: /Users/YOUR_USER/.local/bin/fish +``` + +![iTerm2 Preferences](https://i.imgur.com/VtBUzVH.png) + +Or, you can quit iTerm2 and change the preferences from the command line: + +```bash +#!/bin/bash + +/usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Custom Command' 'Custom Shell'" \ + ~/Library/Preferences/com.googlecode.iterm2.plist + +/usr/libexec/PlistBuddy -c "SET ':New Bookmarks:0:Command' 'Custom Shell' '$HOME/.local/bin/fish'" \ + ~/Library/Preferences/com.googlecode.iterm2.plist +``` + +### How to set fish as the Hyper shell + +Hyper is configured with JavaScript. + +`~/.hyper.js`: + +```js +module.exports = { + config: { + // ... + shell: process.env.HOME + '/.local/bin/fish' + } +}; +``` + +### How to set fish as the Alacritty shell + +`~/.config/alacritty/alacritty.yml` should contain the shell config: + +```yml +shell: + program: /Users/YOUR_USER/.local/bin/fish + args: + - --login +``` + +If you don't yet have an alacritty config, this will do: + +```bash +#!/bin/bash + +mkdir -p ~/.config/alacritty + +cat << EOF >> ~/.config/alacritty/alacritty.yml: +shell: + program: $HOME/.local/bin/fish + args: + - --login +EOF +``` + +The default `alacritty.yml` is included as an _asset_ with each +[Github release](https://github.com/alacritty/alacritty/releases). + +### Where is the fish config? + +Fish will be installed to the standard user location: + +```bash +~/.local/opt/fish/ +``` + +It's config will also go in the standard user location: + +```bash +~/.config/fish/config.fish +``` + +### How to set the default shell back to bash + +See the instructions above for "How to make fish the default shell in _X_", but +use `/bin/bash` as the path instead of `$HOME/.local/bin/fish`. diff --git a/fish/install.sh b/fish/install.sh new file mode 100644 index 0000000..097477d --- /dev/null +++ b/fish/install.sh @@ -0,0 +1,84 @@ +set -e +set -u + +if ! (uname -a | grep -i "darwin" > /dev/null); then + echo "No fish installer for Linux yet. Try this instead:" + echo " sudo apt install -y fish" + exit 1 +fi + +################ +# Install fish # +################ + +# Every package should define these 6 variables +pkg_cmd_name="fish" + +pkg_dst_cmd="$HOME/.local/bin/fish" +pkg_dst="$pkg_dst_cmd" + +pkg_src_cmd="$HOME/.local/opt/fish-v$WEBI_VERSION/bin/fish" +pkg_src_dir="$HOME/.local/opt/fish-v$WEBI_VERSION" +pkg_src="$pkg_src_cmd" + +# pkg_install must be defined by every package + +function _macos_post_install() { + if ! [ -e "$HOME/.local/bin/fish" ]; then + return 0 + fi + + echo "" + echo "Trying to set fish as the default shell..." + echo "" + # stop the caching of preferences + killall cfprefsd + + # Set default Terminal.app shell to fish + defaults write com.apple.Terminal "Shell" -string "$HOME/.local/bin/fish" + echo "To set 'fish' as the default Terminal.app shell:" + echo " Terminal > Preferences > General > Shells open with:" + echo " $HOME/.local/bin/fish" + echo "" + + # Set default iTerm2 shell to fish + if [ -e "$HOME/Library/Preferences/com.googlecode.iterm2.plist" ]; then + /usr/libexec/PlistBuddy \ + -c "SET ':New Bookmarks:0:Custom Command' 'Custom Shell'" \ + $HOME/Library/Preferences/com.googlecode.iterm2.plist + /usr/libexec/PlistBuddy \ + -c "SET ':New Bookmarks:0:Command' $HOME/.local/bin/fish" \ + $HOME/Library/Preferences/com.googlecode.iterm2.plist + echo "To set 'fish' as the default iTerm2 shell:" + echo " iTerm2 > Preferences > Profiles > General > Command >" + echo " Custom Shell: $HOME/.local/bin/fish" + echo "" + fi + + killall cfprefsd +} + +# always try to reset the default shells +_macos_post_install + +function pkg_install() { + mv fish.app/Contents/Resources/base/usr/local "$HOME/.local/opt/fish-v${WEBI_VERSION}" + +} + +function pkg_post_install() { + # don't skip what webi would do automatically + webi_post_install + + # try again to update default shells, now that all files should exist + _macos_post_install +} + +# pkg_get_current_version is recommended, but (soon) not required +function pkg_get_current_version() { + # 'fish --version' has output in this format: + # fish, version 3.1.2 + # This trims it down to just the version number: + # 3.1.2 + echo $(fish --version 2>/dev/null | head -n 1 | cut -d ' ' -f 3) +} diff --git a/fish/releases.js b/fish/releases.js new file mode 100644 index 0000000..d81253f --- /dev/null +++ b/fish/releases.js @@ -0,0 +1,30 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'fish-shell'; +var repo = 'fish-shell'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + all.releases = all.releases + .map(function (rel) { + // We can extract the macos bins from the .app + if (/\.app\.zip$/.test(rel.name)) { + rel.os = 'macos'; + rel.arch = 'amd64'; + return rel; + } + }) + .filter(Boolean); + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); + }); +}