├── SUMMARY.md ├── .github ├── FUNDING.yml ├── release-drafter.yml ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── Support_question.md │ ├── Feature_request.md │ └── Bug_report.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── images ├── preview.gif └── icon-overlap.png ├── functions ├── fish_mode_prompt.fish ├── __sf_util_git_branch.fish ├── __sf_util_set_default.fish ├── __sf_util_truncate_dir.fish ├── __sf_util_human_time.fish ├── fish_right_prompt.fish ├── __sf_section_line_sep.fish ├── __sf_lib_section.fish ├── __sf_section_git_branch.fish ├── __sf_section_exit_code.fish ├── __sf_section_git.fish ├── __sf_section_char.fish ├── __sf_section_conda.fish ├── __sf_section_julia.fish ├── __sf_section_host.fish ├── __sf_section_exec_time.fish ├── __sf_section_venv.fish ├── __sf_section_php.fish ├── fish_prompt.fish ├── __sf_section_haskell.fish ├── __sf_section_time.fish ├── __sf_section_pyenv.fish ├── __sf_section_jobs.fish ├── __sf_section_aws.fish ├── __sf_section_rust.fish ├── __sf_section_kubecontext.fish ├── __sf_section_docker.fish ├── __sf_section_dotnet.fish ├── __sf_section_user.fish ├── __sf_section_ruby.fish ├── __sf_section_golang.fish ├── __sf_section_vi_mode.fish ├── __sf_section_dir.fish ├── __sf_section_elixir.fish ├── __sf_section_node.fish ├── __sf_section_package.fish ├── __sf_section_git_status.fish └── __sf_section_battery.fish ├── scripts └── version.sh ├── .editorconfig ├── tests ├── spacefish_test_setup.fish ├── __sf_util_set_default.test.fish ├── __sf_section_line_sep.test.fish ├── __sf_util_truncate_dir.test.fish ├── run.fish ├── __sf_util_git_branch.test.fish ├── __sf_section_exit_code.test.fish ├── __sf_section_venv.test.fish ├── __sf_section_package.test.fish ├── __sf_util_human_time.test.fish ├── __sf_section_char.test.fish ├── __sf_section_conda.test.fish ├── __sf_section_user.test.fish ├── __sf_section_julia.test.fish ├── __sf_section_time.test.fish ├── __sf_section_aws.test.fish ├── __sf_section_php.test.fish ├── __sf_section_elixir.test.fish ├── __sf_section_jobs.test.fish ├── __sf_lib_section.test.fish ├── __sf_section_kubecontext.test.fish ├── __sf_section_rust.test.fish ├── __sf_section_host.test.fish ├── __sf_section_git_status.test.fish ├── __sf_section_vi_mode.test.fish ├── __sf_section_pyenv.test.fish ├── __sf_section_golang.test.fish ├── __sf_section_dotnet.test.fish ├── __sf_section_node.test.fish ├── __sf_section_docker.test.fish └── __sf_section_dir.test.fish ├── book.json ├── LICENSE ├── .travis.yml ├── package.json ├── docs ├── README.md ├── Troubleshooting.md └── API.md ├── CONTRIBUTING.md ├── CHANGELOG.md ├── .all-contributorsrc └── README.md /SUMMARY.md: -------------------------------------------------------------------------------- 1 | ./docs/README.md -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: matchai 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | _book/ 3 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | template: | 2 | ## What's Changed 3 | 4 | $CHANGES 5 | -------------------------------------------------------------------------------- /images/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matchai/spacefish/HEAD/images/preview.gif -------------------------------------------------------------------------------- /images/icon-overlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matchai/spacefish/HEAD/images/icon-overlap.png -------------------------------------------------------------------------------- /functions/fish_mode_prompt.fish: -------------------------------------------------------------------------------- 1 | function fish_mode_prompt 2 | # Overriden by Spacefish fishshell theme 3 | # To see vi mode in prompt add 'vi_mode' to SPACEFISH_PROMPT_ORDER 4 | end 5 | -------------------------------------------------------------------------------- /functions/__sf_util_git_branch.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Git branch 3 | # 4 | 5 | function __sf_util_git_branch -d "Display the current branch name" 6 | echo (command git rev-parse --abbrev-ref HEAD 2>/dev/null) 7 | end 8 | -------------------------------------------------------------------------------- /scripts/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | new_version=$1 4 | filename=$(pwd)/fish_prompt.fish 5 | 6 | sed -e "s/set -g SPACEFISH_VERSION .*/set -g SPACEFISH_VERSION $new_version/g" $filename > $filename.bak 7 | mv -- $filename.bak $filename 8 | 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.fish] 12 | indent_style = tab 13 | -------------------------------------------------------------------------------- /functions/__sf_util_set_default.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Set default 3 | # 4 | 5 | function __sf_util_set_default -a var -d "Set the default value for a global variable" 6 | if not set -q $var 7 | # Multiple arguments will become a list 8 | set -g $var $argv[2..-1] 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /tests/spacefish_test_setup.fish: -------------------------------------------------------------------------------- 1 | function spacefish_test_setup 2 | # Delete all lingering spacefish variables 3 | set --name | grep -E '^(SPACEFISH_|sf_)' | while read -l var 4 | set -e $var 5 | end 6 | 7 | # Delete lingering mocked functions 8 | for mock in $_mocked 9 | unmock $mock 10 | end 11 | 12 | # Initialize spacefish theme 13 | fish_prompt>/dev/null 14 | end 15 | -------------------------------------------------------------------------------- /tests/__sf_util_set_default.test.fish: -------------------------------------------------------------------------------- 1 | test "Sets a variable" 2 | 'default_value' = ( 3 | __sf_util_set_default my_var 'default_value' 4 | echo $my_var 5 | ) 6 | end 7 | 8 | test "Skips setting a variable if one is already set" 9 | 'default_value' = ( 10 | __sf_util_set_default my_var 'default_value' 11 | __sf_util_set_default my_var 'another_value' 12 | echo $my_var 13 | ) 14 | end 15 | -------------------------------------------------------------------------------- /tests/__sf_section_line_sep.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | test "Echoes a line break" 8 | ( 9 | echo -n -e \n 10 | ) = (__sf_section_line_sep) 11 | end 12 | 13 | test "Disabling SPACEFISH_PROMPT_SEPARATE_LINE doesn't display a line break" 14 | ( 15 | set SPACEFISH_PROMPT_SEPARATE_LINE false 16 | ) = (__sf_section_line_sep) 17 | end 18 | -------------------------------------------------------------------------------- /functions/__sf_util_truncate_dir.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Truncate directory 3 | # 4 | 5 | function __sf_util_truncate_dir -a path truncate_to -d "Truncate a directory path" 6 | if test "$truncate_to" -eq 0 7 | echo $path 8 | else 9 | set -l folders (string split / $path) 10 | 11 | if test (count $folders) -le "$truncate_to" 12 | echo $path 13 | else 14 | echo (string join / $folders[(math 0 - $truncate_to)..-1]) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Support_question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🤗 Support Question 3 | about: If you have a question about configuring Spacefish 💬 4 | 5 | --- 6 | 7 | 14 | -------------------------------------------------------------------------------- /tests/__sf_util_truncate_dir.test.fish: -------------------------------------------------------------------------------- 1 | set path /tmp/$DIRNAME/$TESTNAME 2 | 3 | function setup 4 | mkdir -p $path/temp1/temp2/temp3 5 | cd $path/temp1/temp2/temp3 6 | end 7 | 8 | function teardown 9 | rm -rf $path 10 | end 11 | 12 | test "Truncate path to 1 directory" 13 | 'temp3' = ( 14 | __sf_util_truncate_dir (pwd) 1 15 | ) 16 | end 17 | 18 | test "Truncate path to 3 directories" 19 | 'temp1/temp2/temp3' = ( 20 | __sf_util_truncate_dir (pwd) 3 21 | ) 22 | end 23 | 24 | test "Don't truncate path" 25 | (pwd) = ( 26 | __sf_util_truncate_dir (pwd) 0 27 | ) 28 | end 29 | -------------------------------------------------------------------------------- /functions/__sf_util_human_time.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Human time 3 | # 4 | 5 | function __sf_util_human_time -d "Humanize a time interval for display" 6 | command awk ' 7 | function hmTime(time, stamp) { 8 | split("h:m:s:ms", units, ":") 9 | for (i = 2; i >= -1; i--) { 10 | if (t = int( i < 0 ? time % 1000 : time / (60 ^ i * 1000) % 60 )) { 11 | stamp = stamp t units[sqrt((i - 2) ^ 2) + 1] " " 12 | } 13 | } 14 | if (stamp ~ /^ *$/) { 15 | return "0ms" 16 | } 17 | return substr(stamp, 1, length(stamp) - 1) 18 | } 19 | { 20 | print hmTime($0) 21 | } 22 | ' 23 | end 24 | -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "gitbook": "3.x.x", 3 | "title": "Spacefish", 4 | "plugins": ["edit-link", "github", "github-buttons", "anchorjs", "ga"], 5 | "pluginsConfig": { 6 | "ga": { 7 | "token": "UA-71160903-2" 8 | }, 9 | "edit-link": { 10 | "base": "https://github.com/matchai/spacefish/tree/master", 11 | "label": "Edit This Page" 12 | }, 13 | "github": { 14 | "url": "https://github.com/matchai/spacefish/" 15 | }, 16 | "github-buttons": { 17 | "buttons": [{ 18 | "user": "matchai", 19 | "repo": "spacefish", 20 | "type": "star", 21 | "size": "small", 22 | "count": true 23 | }] 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /functions/fish_right_prompt.fish: -------------------------------------------------------------------------------- 1 | function fish_right_prompt 2 | 3 | # ------------------------------------------------------------------------------ 4 | # Configuration 5 | # ------------------------------------------------------------------------------ 6 | 7 | __sf_util_set_default SPACEFISH_RPROMPT_ORDER "" 8 | 9 | # ------------------------------------------------------------------------------ 10 | # Sections 11 | # ------------------------------------------------------------------------------ 12 | 13 | [ -n "$SPACEFISH_RPROMPT_ORDER" ]; or return 14 | 15 | for i in $SPACEFISH_RPROMPT_ORDER 16 | eval __sf_section_$i 17 | end 18 | set_color normal 19 | end 20 | -------------------------------------------------------------------------------- /functions/__sf_section_line_sep.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Line separator 3 | # 4 | 5 | function __sf_section_line_sep -d "Separate the prompt into two lines" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_PROMPT_SEPARATE_LINE true 11 | 12 | # ------------------------------------------------------------------------------ 13 | # Section 14 | # ------------------------------------------------------------------------------ 15 | 16 | if test "$SPACEFISH_PROMPT_SEPARATE_LINE" = "true" 17 | echo -e -n \n 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /functions/__sf_lib_section.fish: -------------------------------------------------------------------------------- 1 | function __sf_lib_section -a color prefix content suffix 2 | # If there are only 2 args, they are $content and $prefix 3 | if test (count $argv) -eq 2 4 | set content $argv[2] 5 | set prefix 6 | end 7 | 8 | if test "$sf_prompt_opened" = "true" -a "$SPACEFISH_PROMPT_PREFIXES_SHOW" = "true" 9 | # Echo prefixes in bold white 10 | set_color --bold 11 | echo -e -n -s $prefix 12 | set_color normal 13 | end 14 | 15 | # Set the prompt as having been opened 16 | set -g sf_prompt_opened true 17 | 18 | set_color --bold $color 19 | echo -e -n $content 20 | set_color normal 21 | 22 | if test "$SPACEFISH_PROMPT_SUFFIXES_SHOW" = "true" 23 | # Echo suffixes in bold white 24 | set_color --bold 25 | echo -e -n -s $suffix 26 | set_color normal 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Feature Request 3 | about: I have a suggestion (and may want to implement it 🙂)! 4 | 5 | --- 6 | 7 | ## Feature Request 8 | 12 | 13 | **Is your feature request related to a problem? Please describe.** 14 | A clear and concise description of what the problem is. Ex. I have an issue when [...] 15 | 16 | **Describe the solution you'd like** 17 | A clear and concise description of what you want to happen. Add any considered drawbacks. 18 | 19 | **Describe alternatives you've considered** 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | -------------------------------------------------------------------------------- /tests/run.fish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env fish 2 | 3 | set -l gitRoot (git rev-parse --show-toplevel) 4 | set -l testDir (dirname (status --current-filename)) 5 | set -l tmpDir /tmp/spacefish 6 | 7 | # Install fisher if not installed in temporary fish env 8 | if test ! -f $tmpDir/.config/fish/functions/fisher.fish 9 | curl https://git.io/fisher --create-dirs -sLo $tmpDir/.config/fish/functions/fisher.fish 10 | end 11 | 12 | # Install fishtape and local spacefish into temp env 13 | env HOME=$tmpDir fish -c "fisher add jorgebucaran/fishtape@7426171 matchai/fish-mock $gitRoot" 14 | env HOME=$tmpDir fish -c "fish_prompt" 15 | 16 | if test (count $argv) -gt 0 17 | # Run an individual test file if it is provided as an argument 18 | env HOME=$tmpDir fish -c "fishtape $argv[1]" 19 | else 20 | # Otherwise run all test files 21 | env HOME=$tmpDir fish -c "fishtape $testDir/*.test.fish" 22 | end 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: If something isn't working as expected 🤔. 4 | 5 | --- 6 | 7 | ## Bug Report 8 | 9 | **Current Behavior** 10 | A clear and concise description of the behavior. 11 | 12 | **Expected Behavior** 13 | A clear and concise description of what you expected to happen. 14 | 15 | **Relevant `Fish` Configuration** 16 | 17 | ```fish 18 | # Your configuration here 19 | ``` 20 | 21 | **Environment** 22 | - Spacefish version: [the output of `echo $SPACEFISH_VERSION`] 23 | - Fish version: [the output of `fish --version`] 24 | - Fish plugin manager: [e.g. oh-my-fish, fisher, fin] 25 | - Terminal emulator: [e.g. iTerm, Hyper, Terminator] 26 | - Operating system: [e.g. OSX 10.13.4, Windows 10] 27 | 28 | **Possible Solution** 29 | 30 | 31 | **Additional context/Screenshots** 32 | Add any other context about the problem here. If applicable, add screenshots to help explain. 33 | -------------------------------------------------------------------------------- /functions/__sf_section_git_branch.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Git branch 3 | # 4 | 5 | function __sf_section_git_branch -d "Format the displayed branch name" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_GIT_BRANCH_SHOW true 11 | __sf_util_set_default SPACEFISH_GIT_BRANCH_PREFIX $SPACEFISH_GIT_SYMBOL 12 | __sf_util_set_default SPACEFISH_GIT_BRANCH_SUFFIX "" 13 | __sf_util_set_default SPACEFISH_GIT_BRANCH_COLOR magenta 14 | 15 | # ------------------------------------------------------------------------------ 16 | # Section 17 | # ------------------------------------------------------------------------------ 18 | 19 | [ $SPACEFISH_GIT_BRANCH_SHOW = false ]; and return 20 | 21 | set -l git_branch (__sf_util_git_branch) 22 | 23 | [ -z $git_branch ]; and return 24 | 25 | __sf_lib_section \ 26 | $SPACEFISH_GIT_BRANCH_COLOR \ 27 | $SPACEFISH_GIT_BRANCH_PREFIX$git_branch$SPACEFISH_GIT_BRANCH_SUFFIX 28 | end 29 | -------------------------------------------------------------------------------- /functions/__sf_section_exit_code.fish: -------------------------------------------------------------------------------- 1 | # Exit-code 2 | # 3 | 4 | function __sf_section_exit_code -d "Shows the exit code from the previous command." 5 | # ------------------------------------------------------------------------------ 6 | # Configuration 7 | # ------------------------------------------------------------------------------ 8 | 9 | __sf_util_set_default SPACEFISH_EXIT_CODE_SHOW false 10 | __sf_util_set_default SPACEFISH_EXIT_CODE_PREFIX "" 11 | __sf_util_set_default SPACEFISH_EXIT_CODE_SUFFIX " " 12 | __sf_util_set_default SPACEFISH_EXIT_CODE_SYMBOL ✘ 13 | __sf_util_set_default SPACEFISH_EXIT_CODE_COLOR red 14 | 15 | # ------------------------------------------------------------------------------ 16 | # Section 17 | # ------------------------------------------------------------------------------ 18 | 19 | [ $SPACEFISH_EXIT_CODE_SHOW = false ]; or test $sf_exit_code -eq 0; and return 20 | 21 | __sf_lib_section \ 22 | $SPACEFISH_EXIT_CODE_COLOR \ 23 | $SPACEFISH_EXIT_CODE_PREFIX \ 24 | "$SPACEFISH_EXIT_CODE_SYMBOL$sf_exit_code" \ 25 | $SPACEFISH_EXIT_CODE_SUFFIX 26 | end 27 | -------------------------------------------------------------------------------- /tests/__sf_util_git_branch.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mkdir -p /tmp/tmp-spacefish 6 | cd /tmp/tmp-spacefish 7 | command git init >/dev/null 8 | command git config --local user.email "test@example.com" 9 | command git config --local user.name "Test User" 10 | end 11 | 12 | function teardown 13 | rm -rf /tmp/tmp-spacefish 14 | end 15 | 16 | test "Identifies HEAD before initial commit" 17 | ( 18 | echo "HEAD" 19 | ) = (__sf_util_git_branch) 20 | end 21 | 22 | test "Identifies master branch" 23 | ( 24 | command git commit --allow-empty -m "initial commit" --quiet 25 | 26 | echo "master" 27 | ) = (__sf_util_git_branch) 28 | end 29 | 30 | test "Identifies an alternate branch name" 31 | ( 32 | command git checkout -b "testBranch" 2>/dev/null 33 | command git commit --allow-empty -m "initial commit" --quiet 34 | 35 | echo "testBranch" 36 | ) = (__sf_util_git_branch) 37 | end 38 | 39 | test "No result provided for non-git directory" 40 | ( 41 | cd ~ 42 | 43 | echo "" 44 | ) = (__sf_util_git_branch) 45 | end 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Matan Kushner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: stable 3 | env: 4 | global: 5 | - HOMEBREW_NO_AUTO_UPDATE=1 6 | - BREW_FISH2="https://raw.githubusercontent.com/Homebrew/homebrew-core/2827b020c3366ea93566a344167ba62388c16c7d/Formula/fish.rb" 7 | 8 | jobs: 9 | include: 10 | - stage: test 11 | name: "Fish 2.X Linux" 12 | os: linux 13 | sudo: required 14 | install: 15 | - sudo apt-add-repository -y ppa:fish-shell/release-2 16 | - sudo apt-get update 17 | - sudo apt-get install -y fish 18 | 19 | - stage: test 20 | name: "Fish 2.X macOS" 21 | os: osx 22 | install: brew install $BREW_FISH2 23 | 24 | - stage: test 25 | name: "Fish 3.X Linux" 26 | os: linux 27 | sudo: required 28 | install: 29 | - sudo apt-add-repository -y ppa:fish-shell/release-3 30 | - sudo apt-get update 31 | - sudo apt-get install -y fish 32 | 33 | - stage: test 34 | name: "Fish 3.X macOS" 35 | os: osx 36 | install: brew install fish 37 | 38 | - stage: release 39 | provider: script 40 | skip_cleanup: true 41 | script: npx semantic-release 42 | -------------------------------------------------------------------------------- /tests/__sf_section_exit_code.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | test "Exit code not enabled by default" 8 | ( 9 | set sf_exit_code 1 10 | ) = (__sf_section_exit_code) 11 | end 12 | 13 | test "Enable exit-code, shows exit code upon fail" 14 | ( 15 | set SPACEFISH_EXIT_CODE_SHOW true 16 | set sf_exit_code 1 17 | 18 | set_color --bold 19 | set_color normal 20 | set_color --bold red 21 | echo -n "✘1" 22 | set_color normal 23 | set_color --bold 24 | echo -n " " 25 | set_color normal 26 | ) = (__sf_section_exit_code) 27 | end 28 | 29 | test "Hides exit code upon success" 30 | ( 31 | set SPACEFISH_EXIT_CODE_SHOW true 32 | set sf_exit_code 0 33 | ) = (__sf_section_exit_code) 34 | end 35 | 36 | test "Color-changing exit code" 37 | ( 38 | set SPACEFISH_EXIT_CODE_SHOW true 39 | set SPACEFISH_EXIT_CODE_COLOR "purple" 40 | set sf_exit_code 1 41 | 42 | set_color --bold 43 | set_color normal 44 | set_color --bold purple 45 | echo -n "✘1" 46 | set_color normal 47 | set_color --bold 48 | echo -n " " 49 | set_color normal 50 | ) = (__sf_section_exit_code) 51 | end 52 | -------------------------------------------------------------------------------- /functions/__sf_section_git.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Git 3 | # 4 | 5 | function __sf_section_git -d "Display the git branch and status" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_GIT_SHOW true 11 | __sf_util_set_default SPACEFISH_GIT_PREFIX "on " 12 | __sf_util_set_default SPACEFISH_GIT_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 13 | __sf_util_set_default SPACEFISH_GIT_SYMBOL " " 14 | 15 | # ------------------------------------------------------------------------------ 16 | # Section 17 | # ------------------------------------------------------------------------------ 18 | 19 | # Show both git branch and git status: 20 | # spacefish_git_branch 21 | # spacefish_git_status 22 | 23 | [ $SPACEFISH_GIT_SHOW = false ]; and return 24 | 25 | set -l git_branch (__sf_section_git_branch) 26 | set -l git_status (__sf_section_git_status) 27 | 28 | [ -z $git_branch ]; and return 29 | 30 | __sf_lib_section \ 31 | fff \ 32 | $SPACEFISH_GIT_PREFIX \ 33 | "$git_branch$git_status" \ 34 | $SPACEFISH_GIT_SUFFIX 35 | end 36 | -------------------------------------------------------------------------------- /functions/__sf_section_char.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Prompt character 3 | # 4 | 5 | function __sf_section_char -d "Display the prompt character" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_CHAR_PREFIX "" 11 | __sf_util_set_default SPACEFISH_CHAR_SUFFIX " " 12 | __sf_util_set_default SPACEFISH_CHAR_SYMBOL ➜ 13 | __sf_util_set_default SPACEFISH_CHAR_COLOR_SUCCESS green 14 | __sf_util_set_default SPACEFISH_CHAR_COLOR_FAILURE red 15 | 16 | # ------------------------------------------------------------------------------ 17 | # Section 18 | # ------------------------------------------------------------------------------ 19 | 20 | # Color $SPACEFISH_CHAR_SYMBOL red if previous command failed and 21 | # color it in green if the command succeeded. 22 | set -l color 23 | 24 | if test $sf_exit_code -eq 0 25 | set color $SPACEFISH_CHAR_COLOR_SUCCESS 26 | else 27 | set color $SPACEFISH_CHAR_COLOR_FAILURE 28 | end 29 | 30 | __sf_lib_section \ 31 | $color \ 32 | $SPACEFISH_CHAR_PREFIX \ 33 | $SPACEFISH_CHAR_SYMBOL \ 34 | $SPACEFISH_CHAR_SUFFIX 35 | end 36 | -------------------------------------------------------------------------------- /functions/__sf_section_conda.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Conda 3 | # 4 | # Current Conda version. 5 | 6 | function __sf_section_conda -d "Display current Conda version" 7 | # ------------------------------------------------------------------------------ 8 | # Configuration 9 | # ------------------------------------------------------------------------------ 10 | 11 | __sf_util_set_default SPACEFISH_CONDA_SHOW true 12 | __sf_util_set_default SPACEFISH_CONDA_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 13 | __sf_util_set_default SPACEFISH_CONDA_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 14 | __sf_util_set_default SPACEFISH_CONDA_SYMBOL "🅒 " 15 | __sf_util_set_default SPACEFISH_CONDA_COLOR blue 16 | 17 | # ------------------------------------------------------------------------------ 18 | # Section 19 | # ------------------------------------------------------------------------------ 20 | 21 | [ $SPACEFISH_CONDA_SHOW = false ]; and return 22 | 23 | # Show Conda version only if conda is installed and CONDA_DEFAULT_ENV is set 24 | if not type -q conda; \ 25 | or test -z "$CONDA_DEFAULT_ENV"; 26 | return 27 | end 28 | 29 | set -l conda_version (conda -V | string split ' ')[2] 30 | 31 | __sf_lib_section \ 32 | $SPACEFISH_CONDA_COLOR \ 33 | $SPACEFISH_CONDA_PREFIX \ 34 | "$SPACEFISH_CONDA_SYMBOL"v"$conda_version" \ 35 | $SPACEFISH_CONDA_SUFFIX 36 | end 37 | -------------------------------------------------------------------------------- /functions/__sf_section_julia.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Julia 3 | # 4 | # Current Julia version. 5 | 6 | function __sf_section_julia -d "Display julia version" 7 | # ------------------------------------------------------------------------------ 8 | # Configuration 9 | # ------------------------------------------------------------------------------ 10 | 11 | __sf_util_set_default SPACEFISH_JULIA_SHOW true 12 | __sf_util_set_default SPACEFISH_JULIA_PREFIX "is " 13 | __sf_util_set_default SPACEFISH_JULIA_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 14 | __sf_util_set_default SPACEFISH_JULIA_SYMBOL "ஃ " 15 | __sf_util_set_default SPACEFISH_JULIA_COLOR green 16 | 17 | # ------------------------------------------------------------------------------ 18 | # Section 19 | # ------------------------------------------------------------------------------ 20 | 21 | [ $SPACEFISH_JULIA_SHOW = false ]; and return 22 | 23 | # Show Julia version only if julia is installed 24 | type -q julia; or return 25 | 26 | # Show julia version only when pwd has *.jl file(s) 27 | [ (count *.jl) -gt 0 ]; or return 28 | 29 | set -l julia_version (julia --version | grep --color=never -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]') 30 | 31 | __sf_lib_section \ 32 | $SPACEFISH_JULIA_COLOR \ 33 | $SPACEFISH_JULIA_PREFIX \ 34 | "$SPACEFISH_JULIA_SYMBOL"v"$julia_version" \ 35 | $SPACEFISH_JULIA_SUFFIX 36 | end 37 | -------------------------------------------------------------------------------- /tests/__sf_section_venv.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | function teardown 8 | if test "$VIRTUAL_ENV" 9 | set -e VIRTUAL_ENV 10 | end 11 | end 12 | 13 | test "Prints section when \$VIRTUAL_ENV is defined" 14 | ( 15 | set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron" 16 | 17 | set_color --bold 18 | echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX 19 | set_color normal 20 | set_color --bold blue 21 | echo -n "·coolenviron" 22 | set_color normal 23 | set_color --bold 24 | echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX 25 | set_color normal 26 | ) = (__sf_section_venv) 27 | end 28 | 29 | test "Prints section when \$VIRTUAL_ENV is defined with venv as the directory name" 30 | ( 31 | set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron/virtualenv" 32 | 33 | set_color --bold 34 | echo -n $SPACEFISH_PROMPT_DEFAULT_PREFIX 35 | set_color normal 36 | set_color --bold blue 37 | echo -n "·coolenviron" 38 | set_color normal 39 | set_color --bold 40 | echo -n $SPACEFISH_PROMPT_DEFAULT_SUFFIX 41 | set_color normal 42 | ) = (__sf_section_venv) 43 | end 44 | 45 | test "doesn't display the section when SPACEFISH_VENV_SHOW is set to \"false\"" 46 | ( 47 | set VIRTUAL_ENV "/Users/JaneDoe/.venv/coolenviron" 48 | set SPACEFISH_VENV_SHOW false 49 | ) = (__sf_section_venv) 50 | end 51 | -------------------------------------------------------------------------------- /functions/__sf_section_host.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Hostname 3 | # 4 | 5 | 6 | # If there is an ssh connections, current machine name. 7 | function __sf_section_host -d "Display the current hostname if connected over SSH" 8 | 9 | # ------------------------------------------------------------------------------ 10 | # Configuration 11 | # ------------------------------------------------------------------------------ 12 | 13 | __sf_util_set_default SPACEFISH_HOST_SHOW true 14 | __sf_util_set_default SPACEFISH_HOST_PREFIX "at " 15 | __sf_util_set_default SPACEFISH_HOST_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 16 | __sf_util_set_default SPACEFISH_HOST_COLOR blue 17 | __sf_util_set_default SPACEFISH_HOST_COLOR_SSH green 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | [ "$SPACEFISH_HOST_SHOW" = false ]; and return 24 | 25 | if test "$SPACEFISH_HOST_SHOW" = "always"; or set -q SSH_CONNECTION; 26 | 27 | # Determination of what color should be used 28 | set -l host_color 29 | if set -q SSH_CONNECTION; 30 | set host_color $SPACEFISH_HOST_COLOR_SSH 31 | else 32 | set host_color $SPACEFISH_HOST_COLOR 33 | end 34 | 35 | __sf_lib_section \ 36 | $host_color \ 37 | $SPACEFISH_HOST_PREFIX \ 38 | (hostname) \ 39 | $SPACEFISH_HOST_SUFFIX 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /functions/__sf_section_exec_time.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Execution time 3 | # 4 | 5 | function __sf_section_exec_time -d "Display the execution time of the last command" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_EXEC_TIME_SHOW true 11 | __sf_util_set_default SPACEFISH_EXEC_TIME_PREFIX "took " 12 | __sf_util_set_default SPACEFISH_EXEC_TIME_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 13 | __sf_util_set_default SPACEFISH_EXEC_TIME_COLOR yellow 14 | __sf_util_set_default SPACEFISH_EXEC_TIME_ELAPSED 5 15 | 16 | # ------------------------------------------------------------------------------ 17 | # Section 18 | # ------------------------------------------------------------------------------ 19 | 20 | [ $SPACEFISH_EXEC_TIME_SHOW = false ]; and return 21 | 22 | # Allow for compatibility between fish 2.7 and 3.0 23 | set -l command_duration "$CMD_DURATION$cmd_duration" 24 | 25 | if test -n "$command_duration" -a "$command_duration" -gt (math "$SPACEFISH_EXEC_TIME_ELAPSED * 1000") 26 | set -l human_command_duration (echo $command_duration | __sf_util_human_time) 27 | __sf_lib_section \ 28 | $SPACEFISH_EXEC_TIME_COLOR \ 29 | $SPACEFISH_EXEC_TIME_PREFIX \ 30 | $human_command_duration \ 31 | $SPACEFISH_EXEC_TIME_SUFFIX 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /functions/__sf_section_venv.fish: -------------------------------------------------------------------------------- 1 | # virtualenv 2 | # 3 | 4 | function __sf_section_venv -d "Show current virtual Python environment" 5 | # ------------------------------------------------------------------------------ 6 | # Configuration 7 | # ------------------------------------------------------------------------------ 8 | 9 | __sf_util_set_default SPACEFISH_VENV_SHOW true 10 | __sf_util_set_default SPACEFISH_VENV_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 11 | __sf_util_set_default SPACEFISH_VENV_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 12 | __sf_util_set_default SPACEFISH_VENV_SYMBOL "·" 13 | __sf_util_set_default SPACEFISH_VENV_GENERIC_NAMES virtualenv venv .venv 14 | __sf_util_set_default SPACEFISH_VENV_COLOR blue 15 | 16 | # ------------------------------------------------------------------------------ 17 | # Section 18 | # ------------------------------------------------------------------------------ 19 | 20 | # Show venv python version 21 | test $SPACEFISH_VENV_SHOW = false; and return 22 | 23 | # Check if the current directory running via Virtualenv 24 | test -n "$VIRTUAL_ENV"; or return 25 | 26 | set -l venv (basename $VIRTUAL_ENV) 27 | if contains $venv $SPACEFISH_VENV_GENERIC_NAMES 28 | set venv (basename (dirname $VIRTUAL_ENV)) 29 | end 30 | 31 | __sf_lib_section \ 32 | $SPACEFISH_VENV_COLOR \ 33 | $SPACEFISH_VENV_PREFIX \ 34 | "$SPACEFISH_VENV_SYMBOL""$venv" \ 35 | $SPACEFISH_VENV_SUFFIX 36 | end 37 | -------------------------------------------------------------------------------- /functions/__sf_section_php.fish: -------------------------------------------------------------------------------- 1 | # 2 | # PHP 3 | # 4 | # PHP is a server-side scripting language designed primarily for web development. 5 | # Link: http://www.php.net/ 6 | 7 | function __sf_section_php -d "Display the current php version" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_PHP_SHOW true 13 | __sf_util_set_default SPACEFISH_PHP_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_PHP_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_PHP_SYMBOL "🐘 " 16 | __sf_util_set_default SPACEFISH_PHP_COLOR blue 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Show current version of PHP 23 | [ $SPACEFISH_PHP_SHOW = false ]; and return 24 | 25 | # Ensure the php command is available 26 | type -q php; or return 27 | 28 | if not test -f composer.json \ 29 | -o (count *.php) -gt 0 30 | return 31 | end 32 | 33 | set -l php_version (php -v | string match -r 'PHP\s*[0-9.]+' | string split ' ')[2] 34 | 35 | __sf_lib_section \ 36 | $SPACEFISH_PHP_COLOR \ 37 | $SPACEFISH_PHP_PREFIX \ 38 | "$SPACEFISH_PHP_SYMBOL"v"$php_version" \ 39 | $SPACEFISH_PHP_SUFFIX 40 | end 41 | -------------------------------------------------------------------------------- /functions/fish_prompt.fish: -------------------------------------------------------------------------------- 1 | function fish_prompt 2 | # Store the exit code of the last command 3 | set -g sf_exit_code $status 4 | set -g SPACEFISH_VERSION 2.7.0 5 | 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_PROMPT_ADD_NEWLINE true 11 | __sf_util_set_default SPACEFISH_PROMPT_FIRST_PREFIX_SHOW false 12 | __sf_util_set_default SPACEFISH_PROMPT_PREFIXES_SHOW true 13 | __sf_util_set_default SPACEFISH_PROMPT_SUFFIXES_SHOW true 14 | __sf_util_set_default SPACEFISH_PROMPT_DEFAULT_PREFIX "via " 15 | __sf_util_set_default SPACEFISH_PROMPT_DEFAULT_SUFFIX " " 16 | __sf_util_set_default SPACEFISH_PROMPT_ORDER time user dir host git package node ruby golang php rust haskell julia elixir docker aws venv conda pyenv dotnet kubecontext exec_time line_sep battery vi_mode jobs exit_code char 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Sections 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Keep track of whether the prompt has already been opened 23 | set -g sf_prompt_opened $SPACEFISH_PROMPT_FIRST_PREFIX_SHOW 24 | 25 | if test "$SPACEFISH_PROMPT_ADD_NEWLINE" = "true" 26 | echo 27 | end 28 | 29 | for i in $SPACEFISH_PROMPT_ORDER 30 | eval __sf_section_$i 31 | end 32 | set_color normal 33 | end 34 | -------------------------------------------------------------------------------- /functions/__sf_section_haskell.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Haskell Stack 3 | # 4 | # An advanced, purely functional programming language. 5 | # Link: https://www.haskell.org/ 6 | 7 | function __sf_section_haskell -d "Show current version of Haskell Tool Stack" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_HASKELL_SHOW true 13 | __sf_util_set_default SPACEFISH_HASKELL_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_HASKELL_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_HASKELL_SYMBOL "λ " 16 | __sf_util_set_default SPACEFISH_HASKELL_COLOR red 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Show current version of Haskell Tool Stack. 23 | [ $SPACEFISH_HASKELL_SHOW = false ]; and return 24 | 25 | # Ensure the stack command is available 26 | type -q stack; or return 27 | 28 | # If there are stack files in current directory 29 | [ -f ./stack.yaml ]; or return 30 | 31 | set -l haskell_version (stack ghc -- --numeric-version --no-install-ghc) 32 | 33 | __sf_lib_section \ 34 | $SPACEFISH_HASKELL_COLOR \ 35 | $SPACEFISH_HASKELL_PREFIX \ 36 | "$SPACEFISH_HASKELL_SYMBOL"v"$haskell_version" \ 37 | $SPACEFISH_HASKELL_SUFFIX 38 | end 39 | -------------------------------------------------------------------------------- /functions/__sf_section_time.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Time 3 | # 4 | 5 | function __sf_section_time -d "Display the current time!" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_TIME_SHOW false 11 | __sf_util_set_default SPACEFISH_DATE_SHOW false 12 | __sf_util_set_default SPACEFISH_TIME_PREFIX "at " 13 | __sf_util_set_default SPACEFISH_TIME_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 14 | __sf_util_set_default SPACEFISH_TIME_FORMAT false 15 | __sf_util_set_default SPACEFISH_TIME_12HR false 16 | __sf_util_set_default SPACEFISH_TIME_COLOR "yellow" 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | [ $SPACEFISH_TIME_SHOW = false ]; and return 23 | 24 | set -l time_str 25 | 26 | if test $SPACEFISH_DATE_SHOW = true 27 | set time_str (date '+%Y-%m-%d')" " 28 | end 29 | 30 | if not test $SPACEFISH_TIME_FORMAT = false 31 | set time_str "$time_str"(date '+'$SPACEFISH_TIME_FORMAT) 32 | else if test $SPACEFISH_TIME_12HR = true 33 | set time_str "$time_str"(date '+%I:%M:%S') # Fish doesn't seem to have date/time formatting. 34 | else 35 | set time_str "$time_str"(date '+%H:%M:%S') 36 | end 37 | 38 | __sf_lib_section \ 39 | $SPACEFISH_TIME_COLOR \ 40 | $SPACEFISH_TIME_PREFIX \ 41 | $time_str \ 42 | $SPACEFISH_TIME_SUFFIX 43 | end 44 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | ## Motivation and Context 7 | 8 | 9 | Closes # 10 | 11 | ## Types of changes 12 | 13 | - [ ] Bug fix (non-breaking change which fixes an issue) 14 | - [ ] New feature (non-breaking change which adds functionality) 15 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 16 | 17 | ## Screenshots (if appropriate): 18 | 19 | ## How Has This Been Tested? 20 | 21 | 22 | 23 | - [ ] I have tested using **MacOS** 24 | - [ ] I have tested using **Linux** 25 | 26 | ## Checklist: 27 | 28 | 29 | - [ ] I have checked that no other PR duplicates mine 30 | - [ ] My code follows the code style of this project. 31 | - [ ] My change requires a change to the documentation. 32 | - [ ] I have updated the documentation accordingly. 33 | - [ ] I have updated the tests accordingly. 34 | -------------------------------------------------------------------------------- /functions/__sf_section_pyenv.fish: -------------------------------------------------------------------------------- 1 | # pyenv 2 | # 3 | 4 | function __sf_section_pyenv -d "Show current version of pyenv Python, including system." 5 | # ------------------------------------------------------------------------------ 6 | # Configuration 7 | # ------------------------------------------------------------------------------ 8 | 9 | __sf_util_set_default SPACEFISH_PYENV_SHOW true 10 | __sf_util_set_default SPACEFISH_PYENV_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 11 | __sf_util_set_default SPACEFISH_PYENV_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 12 | __sf_util_set_default SPACEFISH_PYENV_SYMBOL "🐍 " 13 | __sf_util_set_default SPACEFISH_PYENV_COLOR yellow 14 | 15 | # ------------------------------------------------------------------------------ 16 | # Section 17 | # ------------------------------------------------------------------------------ 18 | 19 | # Show pyenv python version 20 | [ $SPACEFISH_PYENV_SHOW = false ]; and return 21 | 22 | # Ensure the pyenv command is available 23 | type -q pyenv; or return 24 | 25 | # Show pyenv python version only for Python-specific folders 26 | if not test -n "$PYENV_VERSION" \ 27 | -o -f .python-version \ 28 | -o -f requirements.txt \ 29 | -o -f pyproject.toml \ 30 | -o (count *.py) -gt 0 31 | return 32 | end 33 | 34 | set -l pyenv_status (pyenv version-name 2>/dev/null) # This line needs explicit testing in an enviroment that has pyenv. 35 | 36 | __sf_lib_section \ 37 | $SPACEFISH_PYENV_COLOR \ 38 | $SPACEFISH_PYENV_PREFIX \ 39 | "$SPACEFISH_PYENV_SYMBOL""$pyenv_status" \ 40 | $SPACEFISH_PYENV_SUFFIX 41 | end 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spacefish", 3 | "version": "0.0.0-semantic-release", 4 | "description": "A Fish Shell prompt for Astronauts", 5 | "repository": "git@github.com:matchai/spacefish.git", 6 | "author": "Matan Kushner ", 7 | "scripts": { 8 | "test": "fish tests/run.fish", 9 | "docs:prepare": "gitbook install", 10 | "docs:build": "npm run docs:prepare && gitbook build", 11 | "docs:serve": "npm run docs:prepare && gitbook serve .", 12 | "contributors:add": "all-contributors add", 13 | "contributors:generate": "all-contributors generate" 14 | }, 15 | "license": "MIT", 16 | "devDependencies": { 17 | "@semantic-release/changelog": "^3.0.2", 18 | "@semantic-release/exec": "^3.3.1", 19 | "@semantic-release/git": "^7.0.6", 20 | "all-contributors-cli": "^5.4.1", 21 | "gitbook-cli": "^2.3.2" 22 | }, 23 | "release": { 24 | "plugins": [ 25 | "@semantic-release/commit-analyzer", 26 | "@semantic-release/release-notes-generator", 27 | "@semantic-release/changelog", 28 | [ 29 | "@semantic-release/exec", 30 | { 31 | "prepareCmd": "./scripts/version.sh ${nextRelease.version}" 32 | } 33 | ], 34 | [ 35 | "@semantic-release/git", 36 | { 37 | "assets": [ 38 | "CHANGELOG.md", 39 | "fish_prompt.fish" 40 | ] 41 | } 42 | ], 43 | [ 44 | "@semantic-release/github", 45 | { 46 | "releasedLabels": [ 47 | "Status: Released" 48 | ] 49 | } 50 | ] 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /functions/__sf_section_jobs.fish: -------------------------------------------------------------------------------- 1 | # Jobs 2 | # 3 | 4 | function __sf_section_jobs -d "Show icon, if there's a working jobs in the background." 5 | # ------------------------------------------------------------------------------ 6 | # Configuration 7 | # ------------------------------------------------------------------------------ 8 | 9 | __sf_util_set_default SPACEFISH_JOBS_SHOW true 10 | __sf_util_set_default SPACEFISH_JOBS_PREFIX "" 11 | __sf_util_set_default SPACEFISH_JOBS_SUFFIX " " 12 | __sf_util_set_default SPACEFISH_JOBS_SYMBOL ✦ 13 | __sf_util_set_default SPACEFISH_JOBS_COLOR blue 14 | __sf_util_set_default SPACEFISH_JOBS_AMOUNT_PREFIX "" 15 | __sf_util_set_default SPACEFISH_JOBS_AMOUNT_SUFFIX "" 16 | __sf_util_set_default SPACEFISH_JOBS_AMOUNT_THRESHOLD 1 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | [ $SPACEFISH_JOBS_SHOW = false ]; and return 23 | 24 | set jobs_amount (jobs | wc -l | xargs) # Zsh had a much more complicated command. 25 | 26 | if test $jobs_amount -eq 0 27 | return 28 | end 29 | 30 | if test $jobs_amount -le $SPACEFISH_JOBS_AMOUNT_THRESHOLD 31 | set jobs_amount '' 32 | set SPACEFISH_JOBS_AMOUNT_PREFIX '' 33 | set SPACEFISH_JOBS_AMOUNT_SUFFIX '' 34 | end 35 | 36 | set SPACEFISH_JOBS_SECTION "$SPACEFISH_JOBS_SYMBOL$SPACEFISH_JOBS_AMOUNT_PREFIX$jobs_amount$SPACEFISH_JOBS_AMOUNT_SUFFIX" 37 | 38 | __sf_lib_section \ 39 | $SPACEFISH_JOBS_COLOR \ 40 | $SPACEFISH_JOBS_PREFIX \ 41 | $SPACEFISH_JOBS_SECTION \ 42 | $SPACEFISH_JOBS_SUFFIX 43 | end 44 | -------------------------------------------------------------------------------- /functions/__sf_section_aws.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Amazon Web Services (AWS) 3 | # 4 | # The AWS Command Line Interface (CLI) is a unified tool to manage AWS services. 5 | # Link: https://aws.amazon.com/cli/ 6 | 7 | function __sf_section_aws -d "Display the selected aws profile" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_AWS_SHOW true 13 | __sf_util_set_default SPACEFISH_AWS_PREFIX "using " 14 | __sf_util_set_default SPACEFISH_AWS_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_AWS_SYMBOL "☁️ " 16 | __sf_util_set_default SPACEFISH_AWS_COLOR ff8700 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Show the selected AWS-cli profile 23 | [ $SPACEFISH_AWS_SHOW = false ]; and return 24 | 25 | # Ensure the aws command is available 26 | type -q aws; or return 27 | 28 | set -l PROFILE_NAME 29 | 30 | # if aws-vault is in use, override profile with that 31 | if test -n "$AWS_VAULT" 32 | set PROFILE_NAME "$AWS_VAULT" 33 | else 34 | set PROFILE_NAME "$AWS_PROFILE" 35 | end 36 | 37 | # Early return if there's no named profile, or it's set to default 38 | if test -z "$PROFILE_NAME" \ 39 | -o "$PROFILE_NAME" = "default" 40 | return 41 | end 42 | 43 | __sf_lib_section \ 44 | $SPACEFISH_AWS_COLOR \ 45 | $SPACEFISH_AWS_PREFIX \ 46 | "$SPACEFISH_AWS_SYMBOL""$PROFILE_NAME" \ 47 | $SPACEFISH_AWS_SUFFIX 48 | end 49 | -------------------------------------------------------------------------------- /functions/__sf_section_rust.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Rust 3 | # 4 | # Rust is a systems programming language sponsored by Mozilla Research. 5 | # Link: https://www.rust-lang.org 6 | 7 | function __sf_section_rust -d "Display the current Rust version" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_RUST_SHOW true 13 | __sf_util_set_default SPACEFISH_RUST_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_RUST_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_RUST_SYMBOL "𝗥 " 16 | __sf_util_set_default SPACEFISH_RUST_COLOR red 17 | __sf_util_set_default SPACEFISH_RUST_VERBOSE_VERSION false 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | # Show current version of Rust 24 | [ $SPACEFISH_RUST_SHOW = false ]; and return 25 | 26 | # Ensure the rustc command is available 27 | type -q rustc; or return 28 | 29 | if not test -f Cargo.toml \ 30 | -o (count *.rs) -gt 0 31 | return 32 | end 33 | 34 | set -l rust_version (rustc --version | string split ' ')[2] 35 | 36 | if test $SPACEFISH_RUST_VERBOSE_VERSION = false 37 | set rust_version (string split '-' $rust_version)[1] # Cut off -suffixes from version. "v1.30.0-beta" vs "v1.30.0" 38 | end 39 | 40 | __sf_lib_section \ 41 | $SPACEFISH_RUST_COLOR \ 42 | $SPACEFISH_RUST_PREFIX \ 43 | "$SPACEFISH_RUST_SYMBOL"v"$rust_version" \ 44 | $SPACEFISH_RUST_SUFFIX 45 | end 46 | -------------------------------------------------------------------------------- /tests/__sf_section_package.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock cargo pkgid 0 "echo \"file:///Users/sirMerr/Development/test-rust#0.1.0\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints section when Cargo.toml is present" 15 | ( 16 | touch /tmp/tmp-spacefish/Cargo.toml 17 | 18 | set_color --bold 19 | echo -n "is " 20 | set_color normal 21 | set_color --bold red 22 | echo -n "📦 v0.1.0" 23 | set_color normal 24 | set_color --bold 25 | echo -n " " 26 | set_color normal 27 | ) = (__sf_section_package) 28 | end 29 | 30 | test "Prints section when package.json is present" 31 | ( 32 | echo "{\"version\": \"1.0\"}" > /tmp/tmp-spacefish/package.json 33 | 34 | set_color --bold 35 | echo -n "is " 36 | set_color normal 37 | set_color --bold red 38 | echo -n "📦 v1.0" 39 | set_color normal 40 | set_color --bold 41 | echo -n " " 42 | set_color normal 43 | ) = (__sf_section_package) 44 | end 45 | 46 | test "Changing SPACEFISH_PACKAGE_SUFFIX changes the character suffix" 47 | ( 48 | touch /tmp/tmp-spacefish/Cargo.toml 49 | set SPACEFISH_PACKAGE_SUFFIX · 50 | 51 | set_color --bold 52 | echo -n "is " 53 | set_color normal 54 | set_color --bold red 55 | echo -n "📦 v0.1.0" 56 | set_color normal 57 | set_color --bold 58 | echo -n "·" 59 | set_color normal 60 | ) = (__sf_section_package) 61 | end 62 | 63 | test "Does not print section when Cargo.toml or package.json is not present" 64 | () = (__sf_section_package) 65 | end 66 | 67 | test "Doesn't display the section when SPACEFISH_PACKAGE_SHOW is set to \"false\"" 68 | ( 69 | touch /tmp/tmp-spacefish/Cargo.toml 70 | set SPACEFISH_PACKAGE_SHOW false 71 | ) = (__sf_section_package) 72 | end 73 | -------------------------------------------------------------------------------- /tests/__sf_util_human_time.test.fish: -------------------------------------------------------------------------------- 1 | test "Shows milliseconds" 2 | '1ms' = ( 3 | echo 1 | __sf_util_human_time my_var 4 | ) 5 | end 6 | 7 | test "Shows seconds" 8 | '1s' = ( 9 | echo 1000 | __sf_util_human_time my_var 10 | ) 11 | end 12 | 13 | test "Shows seconds and milliseconds" 14 | '1s 1ms' = ( 15 | echo 1001 | __sf_util_human_time my_var 16 | ) 17 | end 18 | 19 | test "Shows minutes" 20 | '1m' = ( 21 | echo 60000 | __sf_util_human_time my_var 22 | ) 23 | end 24 | 25 | test "Shows minutes and milliseconds" 26 | '1m 1ms' = ( 27 | echo 60001 | __sf_util_human_time my_var 28 | ) 29 | end 30 | 31 | test "Shows minutes and seconds" 32 | '1m 1s' = ( 33 | echo 61000 | __sf_util_human_time my_var 34 | ) 35 | end 36 | 37 | test "Shows minutes, seconds, and milliseconds" 38 | '1m 1s 1ms' = ( 39 | echo 61001 | __sf_util_human_time my_var 40 | ) 41 | end 42 | 43 | test "Shows hours" 44 | '1h' = ( 45 | echo 3600000 | __sf_util_human_time my_var 46 | ) 47 | end 48 | 49 | test "Shows hours and milliseconds" 50 | '1h 1ms' = ( 51 | echo 3600001 | __sf_util_human_time my_var 52 | ) 53 | end 54 | 55 | test "Shows hours and seconds" 56 | '1h 1s' = ( 57 | echo 3601000 | __sf_util_human_time my_var 58 | ) 59 | end 60 | 61 | test "Shows hours, seconds, and milliseconds" 62 | '1h 1s 1ms' = ( 63 | echo 3601001 | __sf_util_human_time my_var 64 | ) 65 | end 66 | 67 | test "Shows hours and minutes" 68 | '1h 1m' = ( 69 | echo 3660000 | __sf_util_human_time my_var 70 | ) 71 | end 72 | 73 | test "Shows hours, minutes, and milliseconds" 74 | '1h 1m 1ms' = ( 75 | echo 3660001 | __sf_util_human_time my_var 76 | ) 77 | end 78 | 79 | test "Shows hours, minutes, and seconds" 80 | '1h 1m 1s' = ( 81 | echo 3661000 | __sf_util_human_time my_var 82 | ) 83 | end 84 | 85 | test "Shows hours, minutes, seconds, and milliseconds" 86 | '1h 1m 1s 1ms' = ( 87 | echo 3661001 | __sf_util_human_time my_var 88 | ) 89 | end 90 | -------------------------------------------------------------------------------- /tests/__sf_section_char.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | test "Displays default char with status code 0" 8 | ( 9 | set sf_exit_code 0 10 | 11 | set_color --bold 12 | echo -n "" 13 | set_color normal 14 | set_color --bold green 15 | echo -n "➜" 16 | set_color normal 17 | set_color --bold 18 | echo -n " " 19 | set_color normal 20 | ) = (__sf_section_char) 21 | end 22 | 23 | test "Displays default char with status code 1" 24 | ( 25 | set sf_exit_code 1 26 | 27 | set_color --bold 28 | echo -n "" 29 | set_color normal 30 | set_color --bold red 31 | echo -n "➜" 32 | set_color normal 33 | set_color --bold 34 | echo -n " " 35 | set_color normal 36 | ) = (__sf_section_char) 37 | end 38 | 39 | test "Changing SPACEFISH_CHAR_SYMBOL changes the displayed character" 40 | ( 41 | set sf_exit_code 0 42 | set SPACEFISH_CHAR_SYMBOL · 43 | 44 | set_color --bold 45 | echo -n "" 46 | set_color normal 47 | set_color --bold green 48 | echo -n "·" 49 | set_color normal 50 | set_color --bold 51 | echo -n " " 52 | set_color normal 53 | ) = (__sf_section_char) 54 | end 55 | 56 | test "Changing SPACEFISH_CHAR_PREFIX changes the character prefix" 57 | ( 58 | set sf_exit_code 0 59 | set SPACEFISH_CHAR_PREFIX · 60 | 61 | set_color --bold 62 | echo -n "·" 63 | set_color normal 64 | set_color --bold green 65 | echo -n "➜" 66 | set_color normal 67 | set_color --bold 68 | echo -n " " 69 | set_color normal 70 | ) = (__sf_section_char) 71 | end 72 | 73 | test "Changing SPACEFISH_CHAR_SYMBOL changes the character suffix" 74 | ( 75 | set sf_exit_code 0 76 | set SPACEFISH_CHAR_SUFFIX · 77 | 78 | set_color --bold 79 | echo -n "" 80 | set_color normal 81 | set_color --bold green 82 | echo -n "➜" 83 | set_color normal 84 | set_color --bold 85 | echo -n "·" 86 | set_color normal 87 | ) = (__sf_section_char) 88 | end 89 | -------------------------------------------------------------------------------- /functions/__sf_section_kubecontext.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Kubernetes (kubectl) 3 | # 4 | # Kubernetes is an open-source system for deployment, scaling, 5 | # and management of containerized applications. 6 | # Link: https://kubernetes.io/ 7 | 8 | function __sf_section_kubecontext -d "Display the kubernetes context" 9 | # ------------------------------------------------------------------------------ 10 | # Configuration 11 | # ------------------------------------------------------------------------------ 12 | 13 | __sf_util_set_default SPACEFISH_KUBECONTEXT_SHOW true 14 | __sf_util_set_default SPACEFISH_KUBECONTEXT_NAMESPACE_SHOW true 15 | __sf_util_set_default SPACEFISH_KUBECONTEXT_PREFIX "at " 16 | __sf_util_set_default SPACEFISH_KUBECONTEXT_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 17 | # Additional space is added because ☸️ is wider than other symbols 18 | # See: https://github.com/denysdovhan/spaceship-prompt/pull/432 19 | __sf_util_set_default SPACEFISH_KUBECONTEXT_SYMBOL "☸️ " 20 | __sf_util_set_default SPACEFISH_KUBECONTEXT_COLOR cyan 21 | 22 | 23 | # ------------------------------------------------------------------------------ 24 | # Section 25 | # ------------------------------------------------------------------------------ 26 | 27 | # Show current kubecontext 28 | [ $SPACEFISH_KUBECONTEXT_SHOW = false ]; and return 29 | # Ensure the kubectl command is available 30 | type -q kubectl; or return 31 | 32 | set -l kube_context (kubectl config current-context 2>/dev/null) 33 | [ -z $kube_context ]; and return 34 | 35 | if test "$SPACEFISH_KUBECONTEXT_NAMESPACE_SHOW" = "true" -a "$kube_context" != "default" 36 | set kube_namespace (kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null) 37 | set kube_context "$kube_context ($kube_namespace)" 38 | end 39 | 40 | __sf_lib_section \ 41 | $SPACEFISH_KUBECONTEXT_COLOR \ 42 | $SPACEFISH_KUBECONTEXT_PREFIX \ 43 | "$SPACEFISH_KUBECONTEXT_SYMBOL""$kube_context" \ 44 | $SPACEFISH_KUBECONTEXT_SUFFIX 45 | end 46 | -------------------------------------------------------------------------------- /functions/__sf_section_docker.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Docker 3 | # 4 | # Current Docker version and Machine name. 5 | 6 | function __sf_section_docker -d "Display docker version and machine name" 7 | # ------------------------------------------------------------------------------ 8 | # Configuration 9 | # ------------------------------------------------------------------------------ 10 | 11 | __sf_util_set_default SPACEFISH_DOCKER_SHOW true 12 | __sf_util_set_default SPACEFISH_DOCKER_PREFIX "is " 13 | __sf_util_set_default SPACEFISH_DOCKER_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 14 | __sf_util_set_default SPACEFISH_DOCKER_SYMBOL "🐳 " 15 | __sf_util_set_default SPACEFISH_DOCKER_COLOR cyan 16 | __sf_util_set_default SPACEFISH_DOCKER_VERBOSE_VERSION false 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | [ $SPACEFISH_DOCKER_SHOW = false ]; and return 23 | 24 | # Show Docker version only if docker is installed 25 | type -q docker; or return 26 | 27 | # Show docker version only when pwd has Dockerfile, docker-compose.yml, .dockerenv in root or COMPOSE_FILE 28 | if not test -f Dockerfile \ 29 | -o -f docker-compose.yml \ 30 | -o -f /.dockerenv \ 31 | -o -f "$COMPOSE_FILE" 32 | return 33 | end 34 | 35 | set -l docker_version (docker version -f "{{.Server.Version}}" 2>/dev/null) 36 | # if docker daemon isn't running you'll get an error like 'Bad response from Docker engine' 37 | [ -z $docker_version ]; and return 38 | 39 | if test "$SPACEFISH_DOCKER_VERBOSE_VERSION" = "false" 40 | set docker_version (string split - $docker_version)[1] 41 | end 42 | 43 | if test -n "$DOCKER_MACHINE_NAME" 44 | set docker_version $docker_version via $DOCKER_MACHINE_NAME 45 | end 46 | 47 | __sf_lib_section \ 48 | $SPACEFISH_DOCKER_COLOR \ 49 | $SPACEFISH_DOCKER_PREFIX \ 50 | "$SPACEFISH_DOCKER_SYMBOL"v"$docker_version" \ 51 | $SPACEFISH_DOCKER_SUFFIX 52 | end 53 | -------------------------------------------------------------------------------- /functions/__sf_section_dotnet.fish: -------------------------------------------------------------------------------- 1 | # 2 | # .NET 3 | # 4 | # .NET Framework is a software framework developed by Microsoft. 5 | # It includes a large class library and provides language interoperability 6 | # across several programming languages. 7 | # Link: https://www.microsoft.com/net 8 | 9 | function __sf_section_dotnet -d "Display the .NET SDK version" 10 | # ------------------------------------------------------------------------------ 11 | # Configuration 12 | # ------------------------------------------------------------------------------ 13 | 14 | __sf_util_set_default SPACEFISH_DOTNET_SHOW true 15 | __sf_util_set_default SPACEFISH_DOTNET_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 16 | __sf_util_set_default SPACEFISH_DOTNET_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 17 | __sf_util_set_default SPACEFISH_DOTNET_SYMBOL ".NET " 18 | __sf_util_set_default SPACEFISH_DOTNET_COLOR "af00d7" # 128 in the original version, but renders as blue in iTerm2? 19 | 20 | # ------------------------------------------------------------------------------ 21 | # Section 22 | # ------------------------------------------------------------------------------ 23 | 24 | # Show current version of .NET SDK 25 | [ $SPACEFISH_DOTNET_SHOW = false ]; and return 26 | 27 | # Ensure the dotnet command is available 28 | type -q dotnet; or return 29 | 30 | if not test -f project.json \ 31 | -o -f global.json \ 32 | -o -f paket.dependencies \ 33 | -o (count *.csproj) -gt 0 \ 34 | -o (count *.fsproj) -gt 0 \ 35 | -o (count *.xproj) -gt 0 \ 36 | -o (count *.sln) -gt 0 37 | return 38 | end 39 | 40 | # From the 41 | # dotnet-cli automatically handles SDK pinning (specified in a global.json file) 42 | # therefore, this already returns the expected version for the current directory 43 | set -l dotnet_version (dotnet --version 2>/dev/null) 44 | 45 | __sf_lib_section \ 46 | $SPACEFISH_DOTNET_COLOR \ 47 | $SPACEFISH_DOTNET_PREFIX \ 48 | "$SPACEFISH_DOTNET_SYMBOL""$dotnet_version" \ 49 | $SPACEFISH_DOTNET_SUFFIX 50 | end 51 | -------------------------------------------------------------------------------- /functions/__sf_section_user.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Username 3 | # 4 | 5 | function __sf_section_user -d "Display the username" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | # -------------------------------------------------------------------------- 11 | # | SPACEFISH_USER_SHOW | show username on local | show username on remote | 12 | # |---------------------+------------------------+-------------------------| 13 | # | false | never | never | 14 | # | always | always | always | 15 | # | true | if needed | always | 16 | # | needed | if needed | if needed | 17 | # -------------------------------------------------------------------------- 18 | 19 | __sf_util_set_default SPACEFISH_USER_SHOW true 20 | __sf_util_set_default SPACEFISH_USER_PREFIX "with " 21 | __sf_util_set_default SPACEFISH_USER_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 22 | __sf_util_set_default SPACEFISH_USER_COLOR yellow 23 | __sf_util_set_default SPACEFISH_USER_COLOR_ROOT red 24 | 25 | # ------------------------------------------------------------------------------ 26 | # Section 27 | # ------------------------------------------------------------------------------ 28 | 29 | [ $SPACEFISH_USER_SHOW = false ]; and return 30 | 31 | if test "$SPACEFISH_USER_SHOW" = "always" \ 32 | -o "$LOGNAME" != "$USER" \ 33 | -o "$UID" = "0" \ 34 | -o \( "$SPACEFISH_USER_SHOW" = "true" -a -n "$SSH_CONNECTION" \) 35 | 36 | set -l user_color 37 | if test "$USER" = "root" 38 | set user_color $SPACEFISH_USER_COLOR_ROOT 39 | else 40 | set user_color $SPACEFISH_USER_COLOR 41 | end 42 | 43 | __sf_lib_section \ 44 | $user_color \ 45 | $SPACEFISH_USER_PREFIX \ 46 | $USER \ 47 | $SPACEFISH_USER_SUFFIX 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /functions/__sf_section_ruby.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Ruby 3 | # 4 | # A dynamic, reflective, object-oriented, general-purpose programming language. 5 | # Link: https://www.ruby-lang.org/ 6 | 7 | function __sf_section_ruby -d "Show current version of Ruby" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_RUBY_SHOW true 13 | __sf_util_set_default SPACEFISH_RUBY_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_RUBY_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_RUBY_SYMBOL "💎 " 16 | __sf_util_set_default SPACEFISH_RUBY_COLOR red 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Check if that user wants to show ruby version 23 | [ $SPACEFISH_RUBY_SHOW = false ]; and return 24 | 25 | # Show versions only for Ruby-specific folders 26 | if not test -f Gemfile \ 27 | -o -f Rakefile \ 28 | -o (count *.rb) -gt 0 29 | return 30 | end 31 | 32 | set -l ruby_version 33 | 34 | if type -q rvm-prompt 35 | set ruby_version (rvm-prompt i v g) 36 | else if type -q rbenv 37 | set ruby_version (rbenv version-name) 38 | else if type -q chruby 39 | set ruby_version $RUBY_AUTO_VERSION 40 | else if type -q asdf 41 | set ruby_version (asdf current ruby | awk '{print $1}') 42 | else 43 | return 44 | end 45 | 46 | [ -z "$ruby_version" -o "$ruby_version" = "system" ]; and return 47 | 48 | # Add 'v' before ruby version that starts with a number 49 | if test -n (echo (string match -r "^[0-9].+\$" "$ruby_version")) 50 | set ruby_version "v$ruby_version" 51 | end 52 | 53 | __sf_lib_section \ 54 | $SPACEFISH_RUBY_COLOR \ 55 | $SPACEFISH_RUBY_PREFIX \ 56 | "$SPACEFISH_RUBY_SYMBOL""$ruby_version" \ 57 | $SPACEFISH_RUBY_SUFFIX 58 | end 59 | -------------------------------------------------------------------------------- /tests/__sf_section_conda.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | set -l LOCAL_CONDA_VERSION 4.5.11 3 | 4 | function setup 5 | spacefish_test_setup 6 | mock conda -V 0 "echo \"conda 4.5.11\"" 7 | mkdir -p /tmp/tmp-spacefish 8 | cd /tmp/tmp-spacefish 9 | end 10 | 11 | function teardown 12 | rm -rf /tmp/tmp-spacefish 13 | if test "$CONDA_DEFAULT_ENV" 14 | set -e CONDA_DEFAULT_ENV 15 | end 16 | end 17 | 18 | test "Prints section when conda is installed and CONDA_DEFAULT_ENV is set" 19 | ( 20 | set -g CONDA_DEFAULT_ENV some-env 21 | 22 | set_color --bold 23 | echo -n "via " 24 | set_color normal 25 | set_color --bold blue 26 | echo -n "🅒 v$LOCAL_CONDA_VERSION" 27 | set_color normal 28 | set_color --bold 29 | echo -n " " 30 | set_color normal 31 | ) = (__sf_section_conda) 32 | end 33 | 34 | test "Changing SPACEFISH_CONDA_SYMBOL changes the displayed character" 35 | ( 36 | set SPACEFISH_CONDA_SYMBOL "· " 37 | set -g CONDA_DEFAULT_ENV some-env 38 | 39 | set_color --bold 40 | echo -n "via " 41 | set_color normal 42 | set_color --bold blue 43 | echo -n "· v$LOCAL_CONDA_VERSION" 44 | set_color normal 45 | set_color --bold 46 | echo -n " " 47 | set_color normal 48 | ) = (__sf_section_conda) 49 | end 50 | 51 | test "Changing SPACEFISH_CONDA_PREFIX changes the character prefix" 52 | ( 53 | set SPACEFISH_CONDA_PREFIX · 54 | set -g CONDA_DEFAULT_ENV some-env 55 | 56 | set_color --bold 57 | echo -n "·" 58 | set_color normal 59 | set_color --bold blue 60 | echo -n "🅒 v$LOCAL_CONDA_VERSION" 61 | set_color normal 62 | set_color --bold 63 | echo -n " " 64 | set_color normal 65 | ) = (__sf_section_conda) 66 | end 67 | 68 | 69 | # Negative 70 | test "Doesn't display section when SPACEFISH_CONDA_SHOW is set to 'false'" 71 | ( 72 | set -g SPACEFISH_CONDA_SHOW false 73 | set -g CONDA_DEFAULT_ENV some-env 74 | ) = (__sf_section_conda) 75 | end 76 | 77 | test "Doesn't display section when CONDA_DEFAULT_ENV is not set" 78 | () = (__sf_section_conda) 79 | end 80 | -------------------------------------------------------------------------------- /functions/__sf_section_golang.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Go 3 | # 4 | # Go is an open source programming language that makes it easy 5 | # to build efficient software. 6 | # Link: https://golang.org/ 7 | 8 | function __sf_section_golang -d "Display the current go version if you're inside GOPATH" 9 | # ------------------------------------------------------------------------------ 10 | # Configuration 11 | # ------------------------------------------------------------------------------ 12 | 13 | __sf_util_set_default SPACEFISH_GOLANG_SHOW true 14 | __sf_util_set_default SPACEFISH_GOLANG_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 15 | __sf_util_set_default SPACEFISH_GOLANG_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 16 | __sf_util_set_default SPACEFISH_GOLANG_SYMBOL "🐹 " 17 | __sf_util_set_default SPACEFISH_GOLANG_COLOR cyan 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | # Show the current version of Golang 24 | [ $SPACEFISH_GOLANG_SHOW = false ]; and return 25 | 26 | # Ensure the go command is available 27 | type -q go; or return 28 | 29 | if not test -f go.mod \ 30 | -o -d Godeps \ 31 | -o -f glide.yaml \ 32 | -o (count *.go) -gt 0 \ 33 | -o -f Gopkg.yml \ 34 | -o -f Gopkg.lock \ 35 | -o ([ (count $GOPATH) -gt 0 ]; and string match $GOPATH $PWD) 36 | return 37 | end 38 | 39 | set -l go_version (go version | string split ' ') 40 | 41 | # Go version is either the commit hash and date (devel +5efe9a8f11 Web Jan 9 07:21:16 2019 +0000) 42 | # at the time of the build or a release tag (go1.11.4) 43 | # https://github.com/matchai/spacefish/issues/137 44 | if test (string match 'devel*' $go_version[3]) 45 | set go_version $go_version[3]":"(string sub -s 2 $go_version[4]) 46 | else 47 | set go_version "v"(string sub -s 3 $go_version[3]) 48 | end 49 | 50 | __sf_lib_section \ 51 | $SPACEFISH_GOLANG_COLOR \ 52 | $SPACEFISH_GOLANG_PREFIX \ 53 | "$SPACEFISH_GOLANG_SYMBOL""$go_version" \ 54 | $SPACEFISH_GOLANG_SUFFIX 55 | end 56 | -------------------------------------------------------------------------------- /functions/__sf_section_vi_mode.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Vi Mode 3 | # 4 | 5 | function __sf_section_vi_mode -d "Display vi mode status" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_VI_MODE_SHOW true 11 | __sf_util_set_default SPACEFISH_VI_MODE_PREFIX " " 12 | __sf_util_set_default SPACEFISH_VI_MODE_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 13 | __sf_util_set_default SPACEFISH_VI_MODE_INSERT [I] 14 | __sf_util_set_default SPACEFISH_VI_MODE_NORMAL [N] 15 | __sf_util_set_default SPACEFISH_VI_MODE_VISUAL [V] 16 | __sf_util_set_default SPACEFISH_VI_MODE_REPLACE_ONE [R] 17 | __sf_util_set_default SPACEFISH_VI_MODE_COLOR white 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | [ $SPACEFISH_VI_MODE_SHOW = false ]; and return 24 | 25 | # Ensure fish_vi_key_bindings or fish_hybrid_key_bindings are used 26 | # Here we are trying to be compatible with default fish_mode_prompt implementation, 27 | # wich handle both "fish_vi_key_bindings" and "fish_hybrid_key_bindings" 28 | [ "$fish_key_bindings" = "fish_vi_key_bindings" ]; or [ "$fish_key_bindings" = "fish_hybrid_key_bindings" ]; or return 29 | 30 | # Use `set -l` to define local variables to avoid populating 31 | # the global namespace 32 | set -l vi_mode_symbol 33 | 34 | # Check current mode and set vi_mode_symbol based on it 35 | switch $fish_bind_mode 36 | case default 37 | set vi_mode_symbol $SPACEFISH_VI_MODE_NORMAL 38 | case insert 39 | set vi_mode_symbol $SPACEFISH_VI_MODE_INSERT 40 | case replace_one 41 | set vi_mode_symbol $SPACEFISH_VI_MODE_REPLACE_ONE 42 | case visual 43 | set vi_mode_symbol $SPACEFISH_VI_MODE_VISUAL 44 | end 45 | 46 | __sf_lib_section \ 47 | $SPACEFISH_VI_MODE_COLOR \ 48 | $SPACEFISH_VI_MODE_PREFIX \ 49 | $vi_mode_symbol \ 50 | $SPACEFISH_VI_MODE_SUFFIX 51 | end 52 | -------------------------------------------------------------------------------- /functions/__sf_section_dir.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Working directory 3 | # 4 | 5 | function __sf_section_dir -d "Display the current truncated directory" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_DIR_SHOW true 11 | __sf_util_set_default SPACEFISH_DIR_PREFIX "in " 12 | __sf_util_set_default SPACEFISH_DIR_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 13 | __sf_util_set_default SPACEFISH_DIR_TRUNC 3 14 | __sf_util_set_default SPACEFISH_DIR_TRUNC_REPO true 15 | __sf_util_set_default SPACEFISH_DIR_COLOR cyan 16 | 17 | # Write Permissions lock symbol 18 | __sf_util_set_default SPACEFISH_DIR_LOCK_SHOW true 19 | __sf_util_set_default SPACEFISH_DIR_LOCK_SYMBOL "" 20 | __sf_util_set_default SPACEFISH_DIR_LOCK_COLOR red 21 | 22 | # ------------------------------------------------------------------------------ 23 | # Section 24 | # ------------------------------------------------------------------------------ 25 | 26 | [ $SPACEFISH_DIR_SHOW = false ]; and return 27 | 28 | set -l dir 29 | set -l tmp 30 | set -l git_root (command git rev-parse --show-toplevel 2>/dev/null) 31 | 32 | if test "$SPACEFISH_DIR_TRUNC_REPO" = "true" -a -n "$git_root" 33 | # Resolve to physical PWD instead of logical 34 | set -l resolvedPWD (pwd -P 2>/dev/null; or pwd) 35 | # Treat repo root as top level directory 36 | set tmp (string replace $git_root (basename $git_root) $resolvedPWD) 37 | else 38 | set -l realhome ~ 39 | set tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) 40 | end 41 | 42 | # Truncate the path to have a limited number of dirs 43 | set dir (__sf_util_truncate_dir $tmp $SPACEFISH_DIR_TRUNC) 44 | 45 | if [ $SPACEFISH_DIR_LOCK_SHOW = true -a ! -w . ] 46 | set DIR_LOCK_SYMBOL (set_color $SPACEFISH_DIR_LOCK_COLOR)" $SPACEFISH_DIR_LOCK_SYMBOL"(set_color --bold) 47 | end 48 | 49 | __sf_lib_section \ 50 | $SPACEFISH_DIR_COLOR \ 51 | $SPACEFISH_DIR_PREFIX \ 52 | $dir \ 53 | "$DIR_LOCK_SYMBOL""$SPACEFISH_DIR_SUFFIX" 54 | end 55 | -------------------------------------------------------------------------------- /tests/__sf_section_user.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | function teardown 8 | set USER $LOGNAME 9 | end 10 | 11 | test "Displays user when different from logname" 12 | ( 13 | set USER spacefishUser 14 | 15 | set_color --bold 16 | echo -n "with " 17 | set_color normal 18 | set_color --bold yellow 19 | echo -n "spacefishUser" 20 | set_color normal 21 | set_color --bold 22 | echo -n " " 23 | set_color normal 24 | ) = (__sf_section_user) 25 | end 26 | 27 | test "Displays user when UID = 0" 28 | ( 29 | set UID 0 30 | 31 | set_color --bold 32 | echo -n "with " 33 | set_color normal 34 | set_color --bold yellow 35 | echo -n $USER 36 | set_color normal 37 | set_color --bold 38 | echo -n " " 39 | set_color normal 40 | ) = (__sf_section_user) 41 | end 42 | 43 | test "Displays user when there's an SSH connection" 44 | ( 45 | set SSH_CONNECTION "192.168.0.100 12345 192.168.0.101 22" 46 | 47 | set_color --bold 48 | echo -n "with " 49 | set_color normal 50 | set_color --bold yellow 51 | echo -n $USER 52 | set_color normal 53 | set_color --bold 54 | echo -n " " 55 | set_color normal 56 | ) = (__sf_section_user) 57 | end 58 | 59 | test "Changes user color when logged in as root" 60 | ( 61 | set USER root 62 | 63 | set_color --bold 64 | echo -n "with " 65 | set_color normal 66 | set_color --bold red 67 | echo -n root 68 | set_color normal 69 | set_color --bold 70 | echo -n " " 71 | set_color normal 72 | ) = (__sf_section_user) 73 | end 74 | 75 | test "Displays user when SPACEFISH_USER_SHOW is set to \"always\"" 76 | ( 77 | set SPACEFISH_USER_SHOW always 78 | 79 | set_color --bold 80 | echo -n "with " 81 | set_color normal 82 | set_color --bold yellow 83 | echo -n $USER 84 | set_color normal 85 | set_color --bold 86 | echo -n " " 87 | set_color normal 88 | ) = (__sf_section_user) 89 | end 90 | 91 | test "Doesn't display user when SPACEFISH_USER_SHOW is set to \"false\"" 92 | ( 93 | set SPACEFISH_USER_SHOW false 94 | ) = (__sf_section_user) 95 | end 96 | -------------------------------------------------------------------------------- /functions/__sf_section_elixir.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Elixir 3 | # 4 | # A dynamic, reflective, object-oriented, general-purpose programming language. 5 | # Link: https://www.elixir-lang.org/ 6 | 7 | function __sf_section_elixir -d "Show current version of Elixir" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_ELIXIR_SHOW true 13 | __sf_util_set_default SPACEFISH_ELIXIR_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_ELIXIR_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_ELIXIR_SYMBOL "💧 " 16 | __sf_util_set_default SPACEFISH_ELIXIR_DEFAULT_VERSION $SPACEFISH_ELIXIR_DEFAULT_VERSION 17 | __sf_util_set_default SPACEFISH_ELIXIR_COLOR magenta 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | # Check if that user wants to show elixir version 24 | [ $SPACEFISH_ELIXIR_SHOW = false ]; and return 25 | 26 | # Show versions only for Elixir-specific folders 27 | if not test -f mix.exs \ 28 | -o (count *.ex) -gt 0 \ 29 | -o (count *.exs) -gt 0 30 | return 31 | end 32 | 33 | set -l elixir_version 34 | 35 | if type -q kiex 36 | set elixir_version $ELIXIR_VERSION 37 | else if type -q exenv 38 | set elixir_version (exenv version-name) 39 | else if type -q elixir 40 | set elixir_version (elixir -v 2>/dev/null | string match -r "Elixir.*" | string split " ")[2] 41 | else 42 | return 43 | end 44 | 45 | [ -z "$elixir_version" -o "$elixir_version" = "system" ]; and return 46 | 47 | # Add 'v' before elixir version that starts with a number 48 | if test -n (echo (string match -r "^[0-9].+\$" "$elixir_version")) 49 | set elixir_version "v$elixir_version" 50 | end 51 | 52 | __sf_lib_section \ 53 | $SPACEFISH_ELIXIR_COLOR \ 54 | $SPACEFISH_ELIXIR_PREFIX \ 55 | "$SPACEFISH_ELIXIR_SYMBOL""$elixir_version" \ 56 | $SPACEFISH_ELIXIR_SUFFIX 57 | end 58 | -------------------------------------------------------------------------------- /functions/__sf_section_node.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Node.js 3 | # 4 | # Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. 5 | # Link: https://nodejs.org/ 6 | 7 | function __sf_section_node -d "Display the local node version" 8 | # ------------------------------------------------------------------------------ 9 | # Configuration 10 | # ------------------------------------------------------------------------------ 11 | 12 | __sf_util_set_default SPACEFISH_NODE_SHOW true 13 | __sf_util_set_default SPACEFISH_NODE_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 14 | __sf_util_set_default SPACEFISH_NODE_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 15 | __sf_util_set_default SPACEFISH_NODE_SYMBOL "⬢ " 16 | __sf_util_set_default SPACEFISH_NODE_DEFAULT_VERSION "" 17 | __sf_util_set_default SPACEFISH_NODE_COLOR green 18 | 19 | # ------------------------------------------------------------------------------ 20 | # Section 21 | # ------------------------------------------------------------------------------ 22 | 23 | # Show the current version of Node 24 | [ $SPACEFISH_NODE_SHOW = false ]; and return 25 | 26 | # Show versions only for Node-specific folders 27 | if not test -f ./package.json \ 28 | -o -d ./node_modules \ 29 | -o (count *.js) -gt 0 30 | return 31 | end 32 | 33 | if type -q nvm 34 | # Only recheck the node version if the nvm bin has changed 35 | if test "$NVM_BIN" != "$sf_last_nvm_bin" -o -z "$sf_node_version" 36 | set -g sf_node_version (nvm current 2>/dev/null) 37 | set -g sf_last_nvm_bin $NVM_BIN 38 | end 39 | else if type -q nodenv 40 | set -g sf_node_version (nodenv version-name 2>/dev/null) 41 | else if type -q node 42 | set -g sf_node_version (node -v 2>/dev/null) 43 | else 44 | return 45 | end 46 | 47 | # Don't echo section if the system verison of node is being used 48 | [ "$sf_node_version" = "system" -o "$sf_node_version" = "node" ]; and return 49 | 50 | # Don't echo section if the node version matches the default version 51 | [ "$sf_node_version" = "$SPACEFISH_NODE_DEFAULT_VERSION" ]; and return 52 | 53 | __sf_lib_section \ 54 | $SPACEFISH_NODE_COLOR \ 55 | $SPACEFISH_NODE_PREFIX \ 56 | "$SPACEFISH_NODE_SYMBOL$sf_node_version" \ 57 | $SPACEFISH_NODE_SUFFIX 58 | end 59 | -------------------------------------------------------------------------------- /tests/__sf_section_julia.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock julia --version 0 "echo \"julia version 1.0.1\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints section when julia is installed and pwd has *.jl file(s)" 15 | ( 16 | touch some-julia-file.jl 17 | 18 | set_color --bold 19 | echo -n "is " 20 | set_color normal 21 | set_color --bold green 22 | echo -n "ஃ v1.0.1" 23 | set_color normal 24 | set_color --bold 25 | echo -n " " 26 | set_color normal 27 | ) = (__sf_section_julia) 28 | end 29 | 30 | test "Changing SPACEFISH_JULIA_SYMBOL changes the displayed character" 31 | ( 32 | set SPACEFISH_JULIA_SYMBOL "· " 33 | touch some-julia-file.jl 34 | 35 | set_color --bold 36 | echo -n "is " 37 | set_color normal 38 | set_color --bold green 39 | echo -n "· v1.0.1" 40 | set_color normal 41 | set_color --bold 42 | echo -n " " 43 | set_color normal 44 | ) = (__sf_section_julia) 45 | end 46 | 47 | test "Changing SPACEFISH_JULIA_PREFIX changes the character prefix" 48 | ( 49 | set SPACEFISH_JULIA_PREFIX · 50 | touch some-julia-file.jl 51 | 52 | set_color --bold 53 | echo -n "·" 54 | set_color normal 55 | set_color --bold green 56 | echo -n "ஃ v1.0.1" 57 | set_color normal 58 | set_color --bold 59 | echo -n " " 60 | set_color normal 61 | ) = (__sf_section_julia) 62 | end 63 | 64 | test "Changing SPACEFISH_JULIA_SUFFIX changes the character suffix" 65 | ( 66 | set SPACEFISH_JULIA_SUFFIX · 67 | touch some-julia-file.jl 68 | 69 | set_color --bold 70 | echo -n "is " 71 | set_color normal 72 | set_color --bold green 73 | echo -n "ஃ v1.0.1" 74 | set_color normal 75 | set_color --bold 76 | echo -n "·" 77 | set_color normal 78 | ) = (__sf_section_julia) 79 | end 80 | 81 | 82 | # Negative 83 | test "Doesn't display section when SPACEFISH_JULIA_SHOW is set to 'false'" 84 | ( 85 | set -g SPACEFISH_JULIA_SHOW false 86 | touch some-julia-file.jl 87 | 88 | ) = (__sf_section_julia) 89 | end 90 | 91 | test "Doesn't display section when pwd has no *.jl file" 92 | () = (__sf_section_julia) 93 | end 94 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Home](README.md) 4 | * [Options](./docs/Options.md) 5 | * [Order](./docs/Options.md#order) 6 | * [Prompt](./docs/Options.md#prompt) 7 | * [Time](./docs/Options.md#time) 8 | * [Username (user)](./docs/Options.md#username-user) 9 | * [Directory (dir)](./docs/Options.md#directory-dir) 10 | * [Hostname (host)](./docs/Options.md#host-host) 11 | * [Git (git)](./docs/Options.md#git-git) 12 | * [Git branch (git_branch)](./docs/Options.md#git-branch-gitbranch) 13 | * [Git status (git_status)](./docs/Options.md#git-status-gitstatus) 14 | * [Package version (package)](./docs/Options.md#package-version-package) 15 | * [Node (node)](./docs/Options.md#nodejs-node) 16 | * [Julia (julia)](./docs/Options.md#julia-julia) 17 | * [Docker (docker)](./docs/Options.md#docker-docker) 18 | * [Ruby (ruby)](./docs/Options.md#ruby-ruby) 19 | * [Haskell (haskell)](./docs/Options.md#haskell-haskell) 20 | * [Conda (conda)](./docs/Options.md#conda-conda) 21 | * [Elixir (elixir)](./docs/Options.md#elixir-elixir) 22 | * [Amazon Web Services (aws)](./docs/Options.md#amazon-web-services-aws-aws) 23 | * [Pyenv (pyenv)](./docs/Options.md#pyenv-pyenv) 24 | * [Go (golang)](./docs/Options.md#go-golang) 25 | * [PHP (php)](./docs/Options.md#php-php) 26 | * [Rust (rust)](./docs/Options.md#rust-rust) 27 | * [.NET (dotnet)](/docs/Options.md#net-dotnet) 28 | * [Kubectl context (kubecontext)](./docs/Options.md#kubectl-context-kubecontext) 29 | * [Execution time (exec_time)](./docs/Options.md#execution-time-exec_time) 30 | * [Line Separator (line_sep)](./docs/Options.md#line_sep-node) 31 | * [Battery (battery)](./docs/Options.md#battery-battery) 32 | * [Jobs (jobs)](./docs/Options.md#jobs-jobs) 33 | * [Exit Code (exit_code)](./docs/Options.md#nodejs-node) 34 | * [Char (char)](./docs/Options.md#char) 35 | * [Contributing Guide](/CONTRIBUTING.md) 36 | * [Philosophy](/CONTRIBUTING.md#philosophy) 37 | * [Setup](/CONTRIBUTING.md#setup) 38 | * [Sections](/CONTRIBUTING.md#sections) 39 | * [API](/docs/API.md) 40 | * [Example section](/docs/API.md#typical-section) 41 | * [SPACEFISH_VERSION](/docs/API.md#spaceshipversion) 42 | * [__sf_lib_section](/docs/API.md#__sf_lib_section-color-prefix-content-suffix) 43 | * [__sf_util_set_default](/docs/API.md#__sf_util_set_default-variable_name-value) 44 | * [__sf_util_git_branch](/docs/API.md#__sf_util_git_branch) 45 | * [Troubleshooting](/docs/Troubleshooting.md) 46 | -------------------------------------------------------------------------------- /tests/__sf_section_time.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | 6 | function date -a time_format 7 | command date --version >/dev/null 2>/dev/null 8 | switch $status 9 | case 0 # GNU Coreutil 10 | command date "-u" "-d @1536116421" "$time_format" 11 | case '*' # MacOS + BSD Compatibility (Lacks --version) 12 | command date "-u" "-r 1536116421" "$time_format" 13 | end 14 | end 15 | end 16 | 17 | function teardown 18 | functions --erase date 19 | end 20 | 21 | test "Time is disabled by default?" 22 | () = (__sf_section_time) 23 | end 24 | 25 | test "Enabling time! 24-hour by default" 26 | ( 27 | set SPACEFISH_TIME_SHOW true 28 | 29 | set_color --bold 30 | echo -n "at " 31 | set_color normal 32 | set_color --bold yellow 33 | echo -n "03:00:21" 34 | set_color normal 35 | set_color --bold 36 | echo -n " " 37 | set_color normal 38 | ) = (__sf_section_time) 39 | end 40 | 41 | test "Enabling time with 12-hour instead" 42 | ( 43 | set SPACEFISH_TIME_SHOW true 44 | set SPACEFISH_TIME_12HR true 45 | 46 | set_color --bold 47 | echo -n "at " 48 | set_color normal 49 | set_color --bold yellow 50 | echo -n "03:00:21" 51 | set_color normal 52 | set_color --bold 53 | echo -n " " 54 | set_color normal 55 | ) = (__sf_section_time) 56 | end 57 | 58 | test "Show the date too" 59 | ( 60 | set SPACEFISH_TIME_SHOW true 61 | set SPACEFISH_DATE_SHOW true 62 | 63 | set_color --bold 64 | echo -n "at " 65 | set_color normal 66 | set_color --bold yellow 67 | echo -n "2018-09-05" 68 | echo -n " " 69 | echo -n "03:00:21" 70 | set_color normal 71 | set_color --bold 72 | echo -n " " 73 | set_color normal 74 | ) = (__sf_section_time) 75 | end 76 | 77 | test "Custom date/time format" 78 | ( 79 | set SPACEFISH_TIME_SHOW true 80 | set SPACEFISH_TIME_FORMAT (date '+%H') # Unix timestamp 81 | set SPACEFISH_TIME_PREFIX "" # Get rid of "at " prefix. 82 | 83 | set_color --bold 84 | set_color normal 85 | set_color --bold yellow 86 | echo -n "03" 87 | set_color normal 88 | set_color --bold 89 | echo -n " " 90 | set_color normal 91 | ) = (__sf_section_time) 92 | end 93 | 94 | test "What is the time? Purple?!" 95 | ( 96 | set SPACEFISH_TIME_SHOW true 97 | set SPACEFISH_TIME_COLOR purple 98 | 99 | set_color --bold 100 | echo -n "at " 101 | set_color normal 102 | set_color --bold purple 103 | echo -n "03:00:21" 104 | set_color normal 105 | set_color --bold 106 | echo -n " " 107 | set_color normal 108 | ) = (__sf_section_time) 109 | end 110 | -------------------------------------------------------------------------------- /tests/__sf_section_aws.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock aws \* 0 6 | set -g AWS_PROFILE user1 7 | end 8 | 9 | test "Prints section when AWS_PROFILE is set" 10 | ( 11 | set_color --bold 12 | echo -n "using " 13 | set_color normal 14 | set_color --bold ff8700 15 | echo -n "☁️ user1" 16 | set_color normal 17 | set_color --bold 18 | echo -n " " 19 | set_color normal 20 | ) = (__sf_section_aws) 21 | end 22 | 23 | test "Doesn't print the section when AWS_PROFILE isn't set" 24 | ( 25 | set --erase AWS_PROFILE 26 | ) = (__sf_section_aws) 27 | end 28 | 29 | test "Doesn't print the section when AWS_PROFILE is set to \"default\"" 30 | ( 31 | set AWS_PROFILE default 32 | ) = (__sf_section_aws) 33 | end 34 | 35 | test "Changing SPACEFISH_AWS_SYMBOL changes the displayed character" 36 | ( 37 | set SPACEFISH_AWS_SYMBOL "· " 38 | 39 | set_color --bold 40 | echo -n "using " 41 | set_color normal 42 | set_color --bold ff8700 43 | echo -n "· user1" 44 | set_color normal 45 | set_color --bold 46 | echo -n " " 47 | set_color normal 48 | ) = (__sf_section_aws) 49 | end 50 | 51 | test "Changing SPACEFISH_AWS_PREFIX changes the character prefix" 52 | ( 53 | set sf_exit_code 0 54 | set SPACEFISH_AWS_PREFIX · 55 | 56 | set_color --bold 57 | echo -n "·" 58 | set_color normal 59 | set_color --bold ff8700 60 | echo -n "☁️ user1" 61 | set_color normal 62 | set_color --bold 63 | echo -n " " 64 | set_color normal 65 | ) = (__sf_section_aws) 66 | end 67 | 68 | test "Changing SPACEFISH_AWS_SUFFIX changes the character suffix" 69 | ( 70 | set sf_exit_code 0 71 | set SPACEFISH_AWS_SUFFIX · 72 | 73 | set_color --bold 74 | echo -n "using " 75 | set_color normal 76 | set_color --bold ff8700 77 | echo -n "☁️ user1" 78 | set_color normal 79 | set_color --bold 80 | echo -n "·" 81 | set_color normal 82 | ) = (__sf_section_aws) 83 | end 84 | 85 | test "doesn't display the section when SPACEFISH_AWS_SHOW is set to \"false\"" 86 | ( 87 | set SPACEFISH_AWS_SHOW false 88 | ) = (__sf_section_aws) 89 | end 90 | 91 | 92 | test "Prints section when AWS_VAULT is set" 93 | ( 94 | set AWS_VAULT user2 95 | set_color --bold 96 | echo -n "using " 97 | set_color normal 98 | set_color --bold ff8700 99 | echo -n "☁️ user2" 100 | set_color normal 101 | set_color --bold 102 | echo -n " " 103 | set_color normal 104 | ) = (__sf_section_aws) 105 | end 106 | -------------------------------------------------------------------------------- /functions/__sf_section_package.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Package 3 | # 4 | # Current package version. 5 | # These package managers supported: 6 | # * NPM 7 | # * Cargo 8 | 9 | function __sf_section_package -d "Display the local package version" 10 | # ------------------------------------------------------------------------------ 11 | # Configuration 12 | # ------------------------------------------------------------------------------ 13 | 14 | __sf_util_set_default SPACEFISH_PACKAGE_SHOW true 15 | __sf_util_set_default SPACEFISH_PACKAGE_PREFIX "is " 16 | __sf_util_set_default SPACEFISH_PACKAGE_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 17 | __sf_util_set_default SPACEFISH_PACKAGE_SYMBOL "📦 " 18 | __sf_util_set_default SPACEFISH_PACKAGE_COLOR red 19 | 20 | # ------------------------------------------------------------------------------ 21 | # Section 22 | # ------------------------------------------------------------------------------ 23 | 24 | [ $SPACEFISH_PACKAGE_SHOW = false ]; and return 25 | 26 | # Exit if there is no package.json or Cargo.toml 27 | if not test -e ./package.json; and not test -e ./Cargo.toml 28 | return 29 | end 30 | 31 | set -l package_version 32 | 33 | # Check if package.json exists AND npm exists locally while supressing output to just exit code (-q) 34 | if type -q npm; and test -f ./package.json 35 | # Check if jq (json handler) exists locally. If yes, check in package.json version 36 | if type -q jq 37 | set package_version (jq -r '.version' package.json 2>/dev/null) 38 | # Check if python exists locally, use json to check version in package.json 39 | else if type -q python 40 | set package_version (python -c "import json; print(json.load(open('package.json'))['version'])" 2>/dev/null) 41 | # Check if node exists locally, use it to check version of package.json 42 | else if type -q node 43 | set package_version (node -p "require('./package.json').version" 2>/dev/null) 44 | end 45 | end 46 | 47 | # Check if Cargo.toml exists and cargo command exists 48 | # and use cargo pkgid to figure out the package 49 | if type -q cargo; and test -f ./Cargo.toml 50 | # Handle missing field `version` in Cargo.toml. 51 | # `cargo pkgid` needs Cargo.lock to exists too. If 52 | # it doesn't, do not show package version 53 | set -l pkgid (cargo pkgid 2>&1) 54 | # Early return on error 55 | echo $pkgid | grep -q "error:"; and return 56 | 57 | # Example input: abc#1.0.0. Example output: 1.0.1 58 | set package_version (string match -r '#(.*)' $pkgid)[2] 59 | end 60 | 61 | if test -z "$package_version" 62 | set package_version ⚠ 63 | else 64 | set package_version "v$package_version" 65 | end 66 | 67 | __sf_lib_section \ 68 | $SPACEFISH_PACKAGE_COLOR \ 69 | $SPACEFISH_PACKAGE_PREFIX \ 70 | "$SPACEFISH_PACKAGE_SYMBOL$package_version" \ 71 | $SPACEFISH_PACKAGE_SUFFIX 72 | end 73 | -------------------------------------------------------------------------------- /tests/__sf_section_php.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock php -v 0 "echo \"PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) ( NTS ) 6 | Copyright (c) 1997-2018 The PHP Group 7 | Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies\"" 8 | mkdir -p /tmp/tmp-spacefish 9 | cd /tmp/tmp-spacefish 10 | end 11 | 12 | function teardown 13 | rm -rf /tmp/tmp-spacefish 14 | end 15 | 16 | test "Prints section when composer.json is present" 17 | ( 18 | touch /tmp/tmp-spacefish/composer.json 19 | 20 | set_color --bold 21 | echo -n "via " 22 | set_color normal 23 | set_color --bold blue 24 | echo -n "🐘 v7.1.16" 25 | set_color normal 26 | set_color --bold 27 | echo -n " " 28 | set_color normal 29 | ) = (__sf_section_php) 30 | end 31 | 32 | test "Prints section when a *.php file is present" 33 | ( 34 | touch /tmp/tmp-spacefish/testfile.php 35 | 36 | set_color --bold 37 | echo -n "via " 38 | set_color normal 39 | set_color --bold blue 40 | echo -n "🐘 v7.1.16" 41 | set_color normal 42 | set_color --bold 43 | echo -n " " 44 | set_color normal 45 | ) = (__sf_section_php) 46 | end 47 | 48 | test "Doesn't print the section when composer.json and *.php aren't present" 49 | () = (__sf_section_php) 50 | end 51 | 52 | test "Changing SPACEFISH_PHP_SYMBOL changes the displayed character" 53 | ( 54 | touch /tmp/tmp-spacefish/composer.json 55 | set SPACEFISH_PHP_SYMBOL "· " 56 | 57 | set_color --bold 58 | echo -n "via " 59 | set_color normal 60 | set_color --bold blue 61 | echo -n "· v7.1.16" 62 | set_color normal 63 | set_color --bold 64 | echo -n " " 65 | set_color normal 66 | ) = (__sf_section_php) 67 | end 68 | 69 | test "Changing SPACEFISH_PHP_PREFIX changes the character prefix" 70 | ( 71 | touch /tmp/tmp-spacefish/composer.json 72 | set sf_exit_code 0 73 | set SPACEFISH_PHP_PREFIX · 74 | 75 | set_color --bold 76 | echo -n "·" 77 | set_color normal 78 | set_color --bold blue 79 | echo -n "🐘 v7.1.16" 80 | set_color normal 81 | set_color --bold 82 | echo -n " " 83 | set_color normal 84 | ) = (__sf_section_php) 85 | end 86 | 87 | test "Changing SPACEFISH_PHP_SUFFIX changes the character suffix" 88 | ( 89 | touch /tmp/tmp-spacefish/composer.json 90 | set sf_exit_code 0 91 | set SPACEFISH_PHP_SUFFIX · 92 | 93 | set_color --bold 94 | echo -n "via " 95 | set_color normal 96 | set_color --bold blue 97 | echo -n "🐘 v7.1.16" 98 | set_color normal 99 | set_color --bold 100 | echo -n "·" 101 | set_color normal 102 | ) = (__sf_section_php) 103 | end 104 | 105 | test "doesn't display the section when SPACEFISH_PHP_SHOW is set to \"false\"" 106 | ( 107 | touch /tmp/tmp-spacefish/composer.json 108 | set SPACEFISH_PHP_SHOW false 109 | ) = (__sf_section_php) 110 | end 111 | -------------------------------------------------------------------------------- /tests/__sf_section_elixir.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock elixir -v 0 "echo \"Erlang/OTP 21 [erts-10.3.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace] 6 | Elixir 1.8.1 (compiled with Erlang/OTP 21)\"" 7 | set -x ELIXIR_VERSION 1.8.1 8 | mkdir -p /tmp/tmp-spacefish 9 | cd /tmp/tmp-spacefish 10 | end 11 | 12 | function teardown 13 | rm -rf /tmp/tmp-spacefish 14 | end 15 | 16 | test "Prints section when mix.exs is present" 17 | ( 18 | touch /tmp/tmp-spacefish/mix.exs 19 | 20 | set_color --bold 21 | echo -n "via " 22 | set_color normal 23 | set_color --bold magenta 24 | echo -n "💧 v1.8.1" 25 | set_color normal 26 | set_color --bold 27 | echo -n " " 28 | set_color normal 29 | ) = (__sf_section_elixir) 30 | end 31 | 32 | test "Prints section when a *.ex file is present" 33 | ( 34 | touch /tmp/tmp-spacefish/testfile.ex 35 | 36 | set_color --bold 37 | echo -n "via " 38 | set_color normal 39 | set_color --bold magenta 40 | echo -n "💧 v1.8.1" 41 | set_color normal 42 | set_color --bold 43 | echo -n " " 44 | set_color normal 45 | ) = (__sf_section_elixir) 46 | end 47 | 48 | test "Doesn't print the section when mix.exs and *.ex aren't present" 49 | () = (__sf_section_elixir) 50 | end 51 | 52 | test "Changing SPACEFISH_ELIXIR_SYMBOL changes the displayed character" 53 | ( 54 | touch /tmp/tmp-spacefish/mix.exs 55 | set SPACEFISH_ELIXIR_SYMBOL "· " 56 | 57 | set_color --bold 58 | echo -n "via " 59 | set_color normal 60 | set_color --bold magenta 61 | echo -n "· v1.8.1" 62 | set_color normal 63 | set_color --bold 64 | echo -n " " 65 | set_color normal 66 | ) = (__sf_section_elixir) 67 | end 68 | 69 | test "Changing SPACEFISH_ELIXIR_PREFIX changes the character prefix" 70 | ( 71 | touch /tmp/tmp-spacefish/mix.exs 72 | set sf_exit_code 0 73 | set SPACEFISH_ELIXIR_PREFIX · 74 | 75 | set_color --bold 76 | echo -n "·" 77 | set_color normal 78 | set_color --bold magenta 79 | echo -n "💧 v1.8.1" 80 | set_color normal 81 | set_color --bold 82 | echo -n " " 83 | set_color normal 84 | ) = (__sf_section_elixir) 85 | end 86 | 87 | test "Changing SPACEFISH_ELIXIR_SUFFIX changes the character suffix" 88 | ( 89 | touch /tmp/tmp-spacefish/mix.exs 90 | set sf_exit_code 0 91 | set SPACEFISH_ELIXIR_SUFFIX · 92 | 93 | set_color --bold 94 | echo -n "via " 95 | set_color normal 96 | set_color --bold magenta 97 | echo -n "💧 v1.8.1" 98 | set_color normal 99 | set_color --bold 100 | echo -n "·" 101 | set_color normal 102 | ) = (__sf_section_elixir) 103 | end 104 | 105 | test "doesn't display the section when SPACEFISH_ELIXIR_SHOW is set to \"false\"" 106 | ( 107 | touch /tmp/tmp-spacefish/mix.exs 108 | set SPACEFISH_ELIXIR_SHOW false 109 | ) = (__sf_section_elixir) 110 | end 111 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | First of all, thank you for contributing. Any contribution is highly appreciated and welcome. 4 | 5 | ## Philosophy 6 | 7 | There's a simple philosophy behind Spacefish: 8 | 9 | * **Absolute parity with spaceship-prompt.** The prompt should be identical to spaceship-prompt when it comes to visuals, functionality, and configuration. 10 | 11 | ## Setup 12 | 13 | 1. **Fork** this repo (click the _fork_ button) 14 | 2. **Clone** your fork to your computer (via `git clone`) 15 | 3. **Make your changes**. Check our [API](./docs/API.md) for more information (we suggest you to check out a new branch for changes). 16 | 4. **Test** your code (via `npm test`) 17 | 5. **Add and commit** your contributions 18 | 6. **Push** your changes to your remote fork 19 | 7. **Open a pull-request** on the spacefish repo 20 | 21 | ## Testing 22 | 23 | Unit tests are stored in the `./tests` directory, with the `(filename).test.fish` naming scheme. 24 | To run the unit tests, simply run: 25 | 26 | ```sh 27 | ./tests/run.fish 28 | ``` 29 | 30 | The unit tests will create their own temporary fish environment, so your local fish and spacefish configuration will not affect the unit test run. 31 | 32 | ## Sections 33 | 34 | Spacefish supports most of the popular programming languages, runtimes, version managers, etc. If it doesn't support something that you need, feel free to open a pull request over at Spaceship, and it will be a candidate to be added to Spacefish. 35 | 36 | ### Will it slow down the prompt? 37 | 38 | Every additional section will slow down the prompt a little bit. If your section performs any expensive checks, find a way to make it faster. 39 | 40 | * **Good:** check if a command exists, check the value of an environment variable 41 | * **Bad:** network requests, reading large files, etc 42 | 43 | ## Documentation 44 | 45 | When updating documentation for your section, make sure the markdown document is being properly rendered by Github. Specifically, the following common pitfalls have already been discovered: 46 | 47 | * Empty inline code blocks ` ` will only be rendered if you put at least one non-breaking whitespace " " inside, like so: `` ` ` `` → ` ` 48 | * Leading and trailing whitespaces in inline code blocks will be stripped, to indicate that a whitespace is present, use the middot symbol `·`, like so: `` `🐟·` `` → `🐟·` 49 | 50 | ## Add yourself as a contributor 51 | 52 | This project follows the [all contributors](https://github.com/kentcdodds/all-contributors) specification. To add yourself to the table of 53 | contributors on the README.md, please use the automated script as part of your PR: 54 | 55 | ```console 56 | npm install 57 | npm run contributors:add -- 58 | ``` 59 | 60 | Follow the prompt. If you've already added yourself to the list and are making a new type of contribution, you can run 61 | it again and select the added contribution type. 62 | 63 | **Thank you for reading the contribution guide! Happy hacking!** 64 | -------------------------------------------------------------------------------- /tests/__sf_section_jobs.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | function teardown 8 | killall sleep # Kill any previous background jobs 9 | end 10 | 11 | test "Test a single background job" 12 | ( 13 | sleep 5 & # Background process 14 | 15 | set_color --bold 16 | set_color normal 17 | set_color --bold blue 18 | echo -n "✦" 19 | set_color normal 20 | set_color --bold 21 | echo -n " " 22 | set_color normal 23 | ) = (__sf_section_jobs) 24 | end 25 | 26 | test "Test with two background jobs" 27 | ( 28 | sleep 5 & # Background process #1 29 | sleep 5 & # Background process #2 30 | 31 | set_color --bold 32 | set_color normal 33 | set_color --bold blue 34 | echo -n "✦2" 35 | set_color normal 36 | set_color --bold 37 | echo -n " " 38 | set_color normal 39 | ) = (__sf_section_jobs) 40 | end 41 | 42 | test "Test with five background jobs" 43 | ( 44 | sleep 5 & # Background process #1 45 | sleep 5 & # Background process #2 46 | sleep 5 & # Background process #3 47 | sleep 5 & # Background process #4 48 | sleep 5 & # Background process #5 49 | 50 | set_color --bold 51 | set_color normal 52 | set_color --bold blue 53 | echo -n "✦5" 54 | set_color normal 55 | set_color --bold 56 | echo -n " " 57 | set_color normal 58 | ) = (__sf_section_jobs) 59 | end 60 | 61 | test "Test with less than threshold of background jobs" 62 | ( 63 | set SPACEFISH_JOBS_AMOUNT_THRESHOLD 4 64 | 65 | sleep 5 & # Background process #1 66 | sleep 5 & # Background process #2 67 | sleep 5 & # Background process #3 68 | 69 | set_color --bold 70 | set_color normal 71 | set_color --bold blue 72 | echo -n "✦" 73 | set_color normal 74 | set_color --bold 75 | echo -n " " 76 | set_color normal 77 | ) = (__sf_section_jobs) 78 | end 79 | 80 | test "Test with equal threshold of background jobs" 81 | ( 82 | set SPACEFISH_JOBS_AMOUNT_THRESHOLD 4 83 | 84 | sleep 5 & # Background process #1 85 | sleep 5 & # Background process #2 86 | sleep 5 & # Background process #3 87 | sleep 5 & # Background process #4 88 | 89 | set_color --bold 90 | set_color normal 91 | set_color --bold blue 92 | echo -n "✦" 93 | set_color normal 94 | set_color --bold 95 | echo -n " " 96 | set_color normal 97 | ) = (__sf_section_jobs) 98 | end 99 | 100 | test "Test with more than threshold of background jobs" 101 | ( 102 | set SPACEFISH_JOBS_AMOUNT_THRESHOLD 4 103 | 104 | sleep 5 & # Background process #1 105 | sleep 5 & # Background process #2 106 | sleep 5 & # Background process #3 107 | sleep 5 & # Background process #4 108 | sleep 5 & # Background process #5 109 | sleep 5 & # Background process #6 110 | 111 | set_color --bold 112 | set_color normal 113 | set_color --bold blue 114 | echo -n "✦6" 115 | set_color normal 116 | set_color --bold 117 | echo -n " " 118 | set_color normal 119 | ) = (__sf_section_jobs) 120 | end 121 | -------------------------------------------------------------------------------- /tests/__sf_lib_section.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | test "Displays only the colored content when 2 arguments are passed" 8 | ( 9 | set_color --bold 10 | echo -n "" 11 | set_color normal 12 | set_color --bold red 13 | echo -n "test content" 14 | set_color normal 15 | set_color --bold 16 | echo -n "" 17 | set_color normal 18 | ) = (__sf_lib_section red "test content") 19 | end 20 | 21 | test "Displays the prefix, colored content and suffix when 4 arguments are passed" 22 | ( 23 | set_color --bold 24 | echo -n "prefix" 25 | set_color normal 26 | set_color --bold red 27 | echo -n "test content" 28 | set_color normal 29 | set_color --bold 30 | echo -n "suffix" 31 | set_color normal 32 | ) = (__sf_lib_section red prefix "test content" suffix) 33 | end 34 | 35 | test "Displays the prefix if prefixes are enabled" 36 | ( 37 | set SPACEFISH_PROMPT_PREFIXES_SHOW true 38 | 39 | set_color --bold 40 | echo -n "prefix" 41 | set_color normal 42 | set_color --bold red 43 | echo -n "test content" 44 | set_color normal 45 | set_color --bold 46 | echo -n "suffix" 47 | set_color normal 48 | ) = (__sf_lib_section red prefix "test content" suffix) 49 | end 50 | 51 | test "Doesn't display the prefix if prefixes are disabled" 52 | ( 53 | set SPACEFISH_PROMPT_PREFIXES_SHOW false 54 | 55 | set_color --bold red 56 | echo -n "test content" 57 | set_color normal 58 | set_color --bold 59 | echo -n "suffix" 60 | set_color normal 61 | ) = (__sf_lib_section red prefix "test content" suffix) 62 | end 63 | 64 | test "Displays the suffix if suffixes are enabled" 65 | ( 66 | set SPACEFISH_PROMPT_SUFFIXES_SHOW true 67 | 68 | set_color --bold 69 | echo -n "prefix" 70 | set_color normal 71 | set_color --bold red 72 | echo -n "test content" 73 | set_color normal 74 | set_color --bold 75 | echo -n "suffix" 76 | set_color normal 77 | ) = (__sf_lib_section red prefix "test content" suffix) 78 | end 79 | 80 | test "Doesn't display the suffix if suffixes are disabled" 81 | ( 82 | set SPACEFISH_PROMPT_SUFFIXES_SHOW false 83 | 84 | set_color --bold 85 | echo -n "prefix" 86 | set_color normal 87 | set_color --bold red 88 | echo -n "test content" 89 | set_color normal 90 | ) = (__sf_lib_section red prefix "test content" suffix) 91 | end 92 | 93 | test "Only prints the prefix for the second consecutive section" 94 | ( 95 | set sf_prompt_opened false 96 | 97 | set_color --bold red 98 | echo -n "test content 1" 99 | set_color normal 100 | set_color --bold 101 | echo -n "suffix 1" 102 | set_color normal 103 | 104 | set_color --bold 105 | echo -n "prefix 2" 106 | set_color normal 107 | set_color --bold red 108 | echo -n "test content 2" 109 | set_color normal 110 | set_color --bold 111 | echo -n "suffix 2" 112 | set_color normal 113 | ) = ( 114 | __sf_lib_section red "prefix 1" "test content 1" "suffix 1" 115 | __sf_lib_section red "prefix 2" "test content 2" "suffix 2" 116 | ) 117 | end 118 | -------------------------------------------------------------------------------- /tests/__sf_section_kubecontext.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock kubectl config 0 "echo \"testkube\"" 6 | end 7 | 8 | test "Prints section" 9 | ( 10 | set_color --bold 11 | echo -n "at " 12 | set_color normal 13 | set_color --bold cyan 14 | echo -n "☸️ testkube (testkube)" 15 | set_color normal 16 | set_color --bold 17 | echo -n " " 18 | set_color normal 19 | ) = (__sf_section_kubecontext) 20 | end 21 | 22 | test "Kubecontext symbol does not appear outside of a Kubernetes project" 23 | ( 24 | mock kubectl config 1 25 | ) = (__sf_section_kubecontext) 26 | end 27 | 28 | test "Changing SPACEFISH_KUBECONTEXT_SYMBOL changes the displayed character" 29 | ( 30 | set SPACEFISH_KUBECONTEXT_SYMBOL "· " 31 | 32 | set_color --bold 33 | echo -n "at " 34 | set_color normal 35 | set_color --bold cyan 36 | echo -n "· testkube (testkube)" 37 | set_color normal 38 | set_color --bold 39 | echo -n " " 40 | set_color normal 41 | ) = (__sf_section_kubecontext) 42 | end 43 | 44 | test "Changing SPACEFISH_KUBECONTEXT_PREFIX changes the character prefix" 45 | ( 46 | set sf_exit_code 0 47 | set SPACEFISH_KUBECONTEXT_PREFIX · 48 | 49 | set_color --bold 50 | echo -n "·" 51 | set_color normal 52 | set_color --bold cyan 53 | echo -n "☸️ testkube (testkube)" 54 | set_color normal 55 | set_color --bold 56 | echo -n " " 57 | set_color normal 58 | ) = (__sf_section_kubecontext) 59 | end 60 | 61 | test "Changing SPACEFISH_KUBECONTEXT_SUFFIX changes the character suffix" 62 | ( 63 | set sf_exit_code 0 64 | set SPACEFISH_KUBECONTEXT_SUFFIX · 65 | 66 | set_color --bold 67 | echo -n "at " 68 | set_color normal 69 | set_color --bold cyan 70 | echo -n "☸️ testkube (testkube)" 71 | set_color normal 72 | set_color --bold 73 | echo -n "·" 74 | set_color normal 75 | ) = (__sf_section_kubecontext) 76 | end 77 | 78 | test "Doesn't display the section when SPACEFISH_KUBECONTEXT_SHOW is set to \"false\"" 79 | ( 80 | set SPACEFISH_KUBECONTEXT_SHOW false 81 | ) = (__sf_section_kubecontext) 82 | end 83 | 84 | test "Doesn't display the namespace section when SPACEFISH_KUBECONTEXT_NAMESPACE_SHOW is set to \"false\"" 85 | ( 86 | set SPACEFISH_KUBECONTEXT_NAMESPACE_SHOW false 87 | set sf_exit_code 0 88 | set SPACEFISH_KUBECONTEXT_SUFFIX · 89 | 90 | set_color --bold 91 | echo -n "at " 92 | set_color normal 93 | set_color --bold cyan 94 | echo -n "☸️ testkube" 95 | set_color normal 96 | set_color --bold 97 | echo -n "·" 98 | set_color normal 99 | ) = (__sf_section_kubecontext) 100 | end 101 | 102 | test "Doesn't display the namespace section when kube_context is set to \"default\"" 103 | ( 104 | mock kubectl config 0 "echo \"default\"" 105 | 106 | set sf_exit_code 0 107 | set SPACEFISH_KUBECONTEXT_SUFFIX · 108 | 109 | set_color --bold 110 | echo -n "at " 111 | set_color normal 112 | set_color --bold cyan 113 | echo -n "☸️ default" 114 | set_color normal 115 | set_color --bold 116 | echo -n "·" 117 | set_color normal 118 | ) = (__sf_section_kubecontext) 119 | end 120 | -------------------------------------------------------------------------------- /tests/__sf_section_rust.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock rustc --version 0 "echo \"rustc 1.28.0-nightly (9634041f0 2018-07-30)\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints section when Cargo.toml is present" 15 | ( 16 | touch /tmp/tmp-spacefish/Cargo.toml 17 | 18 | set_color --bold 19 | echo -n "via " 20 | set_color normal 21 | set_color --bold red 22 | echo -n "𝗥 v1.28.0" 23 | set_color normal 24 | set_color --bold 25 | echo -n " " 26 | set_color normal 27 | ) = (__sf_section_rust) 28 | end 29 | 30 | test "Prints section when a *.rs file is present" 31 | ( 32 | touch /tmp/tmp-spacefish/testfile.rs 33 | 34 | set_color --bold 35 | echo -n "via " 36 | set_color normal 37 | set_color --bold red 38 | echo -n "𝗥 v1.28.0" 39 | set_color normal 40 | set_color --bold 41 | echo -n " " 42 | set_color normal 43 | ) = (__sf_section_rust) 44 | end 45 | 46 | test "Doesn't print the section when Cargo.toml and *.rs aren't present" 47 | () = (__sf_section_rust) 48 | end 49 | 50 | test "Changing SPACEFISH_RUST_SYMBOL changes the displayed character" 51 | ( 52 | touch /tmp/tmp-spacefish/Cargo.toml 53 | set SPACEFISH_RUST_SYMBOL "· " 54 | 55 | set_color --bold 56 | echo -n "via " 57 | set_color normal 58 | set_color --bold red 59 | echo -n "· v1.28.0" 60 | set_color normal 61 | set_color --bold 62 | echo -n " " 63 | set_color normal 64 | ) = (__sf_section_rust) 65 | end 66 | 67 | test "Changing SPACEFISH_RUST_PREFIX changes the character prefix" 68 | ( 69 | touch /tmp/tmp-spacefish/Cargo.toml 70 | set sf_exit_code 0 71 | set SPACEFISH_RUST_PREFIX · 72 | 73 | set_color --bold 74 | echo -n "·" 75 | set_color normal 76 | set_color --bold red 77 | echo -n "𝗥 v1.28.0" 78 | set_color normal 79 | set_color --bold 80 | echo -n " " 81 | set_color normal 82 | ) = (__sf_section_rust) 83 | end 84 | 85 | test "Changing SPACEFISH_RUST_SUFFIX changes the character suffix" 86 | ( 87 | touch /tmp/tmp-spacefish/Cargo.toml 88 | set sf_exit_code 0 89 | set SPACEFISH_RUST_SUFFIX · 90 | 91 | set_color --bold 92 | echo -n "via " 93 | set_color normal 94 | set_color --bold red 95 | echo -n "𝗥 v1.28.0" 96 | set_color normal 97 | set_color --bold 98 | echo -n "·" 99 | set_color normal 100 | ) = (__sf_section_rust) 101 | end 102 | 103 | test "Prints verbose version when configured to do so" 104 | ( 105 | touch /tmp/tmp-spacefish/Cargo.toml 106 | set SPACEFISH_RUST_VERBOSE_VERSION true 107 | 108 | set_color --bold 109 | echo -n "via " 110 | set_color normal 111 | set_color --bold red 112 | echo -n "𝗥 v1.28.0-nightly" 113 | set_color normal 114 | set_color --bold 115 | echo -n " " 116 | set_color normal 117 | ) = (__sf_section_rust) 118 | end 119 | 120 | test "doesn't display the section when SPACEFISH_RUST_SHOW is set to \"false\"" 121 | ( 122 | touch /tmp/tmp-spacefish/Cargo.toml 123 | set SPACEFISH_RUST_SHOW false 124 | ) = (__sf_section_rust) 125 | end 126 | -------------------------------------------------------------------------------- /tests/__sf_section_host.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | end 6 | 7 | function teardown 8 | if set -q SSH_CONNECTION; 9 | set --erase SSH_CONNECTION 10 | end 11 | end 12 | 13 | test "Correctly shows hostname upon SSH connection" 14 | ( 15 | set SSH_CONNECTION "192.168.0.100 12345 192.168.0.101 22" 16 | 17 | set_color --bold 18 | echo -n "at " 19 | set_color normal 20 | set_color --bold green 21 | echo -n (hostname) 22 | set_color normal 23 | set_color --bold 24 | echo -n " " 25 | set_color normal 26 | ) = (__sf_section_host) 27 | end 28 | 29 | test "Displays user when SPACEFISH_HOST_SHOW is set to \"always\"" 30 | ( 31 | set SPACEFISH_HOST_SHOW always 32 | 33 | set_color --bold 34 | echo -n "at " 35 | set_color normal 36 | set_color --bold blue 37 | echo -n (hostname) 38 | set_color normal 39 | set_color --bold 40 | echo -n " " 41 | set_color normal 42 | ) = (__sf_section_host) 43 | end 44 | 45 | test "Displays user when SPACEFISH_HOST_SHOW is set to \"always\", over SSH" 46 | ( 47 | set SPACEFISH_HOST_SHOW always 48 | set SSH_CONNECTION "192.168.0.100 12345 192.168.0.101 22" 49 | 50 | set_color --bold 51 | echo -n "at " 52 | set_color normal 53 | set_color --bold green 54 | echo -n (hostname) 55 | set_color normal 56 | set_color --bold 57 | echo -n " " 58 | set_color normal 59 | ) = (__sf_section_host) 60 | end 61 | 62 | test "doesn't display the section when SPACEFISH_HOST_SHOW is set to \"false\"" 63 | ( 64 | set SPACEFISH_HOST_SHOW false 65 | ) = (__sf_section_host) 66 | end 67 | 68 | test "Displays hostname when set different from machine name, over SSH" 69 | ( 70 | mock hostname \* 0 "echo \"spacefish\"" 71 | set SSH_CONNECTION "192.168.0.100 12345 192.168.0.101 22" 72 | 73 | set_color --bold 74 | echo -n "at " 75 | set_color normal 76 | set_color --bold green 77 | echo -n "spacefish" 78 | set_color normal 79 | set_color --bold 80 | echo -n " " 81 | set_color normal 82 | ) = (__sf_section_host) 83 | end 84 | 85 | test "Doesn't display hostname by default, without SSH" 86 | () = (__sf_section_host) 87 | end 88 | 89 | # Color testing; magenta = pass, red = failure. 90 | test "Test color, no SSH." 91 | ( 92 | set SPACEFISH_HOST_COLOR "magenta" # No SSH connection. This should display. 93 | set SPACEFISH_HOST_COLOR_SSH "red" # If red shows, test failed. 94 | set SPACEFISH_HOST_SHOW always 95 | 96 | set_color --bold 97 | echo -n "at " 98 | set_color normal 99 | set_color --bold "magenta" 100 | echo -n (hostname) 101 | set_color normal 102 | set_color --bold 103 | echo -n " " 104 | set_color normal 105 | ) = (__sf_section_host) 106 | end 107 | 108 | test "Test color, with SSH." 109 | ( 110 | set SPACEFISH_HOST_COLOR "red" # If red shows, test failed. 111 | set SPACEFISH_HOST_COLOR_SSH "magenta" # SSH connection exists. This should take precedence. 112 | set SSH_CONNECTION "192.168.0.100 12345 192.168.0.101 22" 113 | 114 | set_color --bold 115 | echo -n "at " 116 | set_color normal 117 | set_color --bold "magenta" 118 | echo -n (hostname) 119 | set_color normal 120 | set_color --bold 121 | echo -n " " 122 | set_color normal 123 | ) = (__sf_section_host) 124 | end 125 | -------------------------------------------------------------------------------- /tests/__sf_section_git_status.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mkdir -p /tmp/tmp-spacefish 6 | cd /tmp/tmp-spacefish 7 | command git init >/dev/null 8 | command git config --local user.email "test@example.com" 9 | command git config --local user.name "Test User" 10 | end 11 | 12 | function teardown 13 | rm -rf /tmp/tmp-spacefish 14 | end 15 | 16 | test "Displays no status symbols in a clean repo" 17 | () = (__sf_section_git_status) 18 | end 19 | 20 | test "Displays the correct symbol for untracked file" 21 | ( 22 | touch testfile 23 | 24 | set_color --bold 25 | set_color normal 26 | set_color --bold red 27 | echo -n " [?]" 28 | set_color normal 29 | set_color --bold 30 | set_color normal 31 | ) = (__sf_section_git_status) 32 | end 33 | 34 | test "Displays the correct symbol for added file" 35 | ( 36 | touch testfile 37 | command git add testfile 38 | 39 | set_color --bold 40 | set_color normal 41 | set_color --bold red 42 | echo -n " [+]" 43 | set_color normal 44 | set_color --bold 45 | set_color normal 46 | ) = (__sf_section_git_status) 47 | end 48 | 49 | test "Displays the correct symbol for modified file" 50 | ( 51 | touch testfile 52 | command git add testfile 53 | command git commit -m "Initial commit" --quiet 54 | echo "modification" > testfile 55 | 56 | set_color --bold 57 | set_color normal 58 | set_color --bold red 59 | echo -n " [!]" 60 | set_color normal 61 | set_color --bold 62 | set_color normal 63 | ) = (__sf_section_git_status) 64 | end 65 | 66 | test "Displays the correct symbol for renamed file" 67 | ( 68 | touch testfile 69 | command git add testfile 70 | command git commit -m "Initial commit" --quiet 71 | mv testfile newtestfile 72 | command git add testfile newtestfile 73 | 74 | set_color --bold 75 | set_color normal 76 | set_color --bold red 77 | echo -n " [»]" 78 | set_color normal 79 | set_color --bold 80 | set_color normal 81 | ) = (__sf_section_git_status) 82 | end 83 | 84 | test "Displays the correct symbol for deleted file" 85 | ( 86 | touch testfile 87 | command git add testfile 88 | command git commit -m "Initial commit" --quiet 89 | rm testfile 90 | command git add testfile 91 | 92 | set_color --bold 93 | set_color normal 94 | set_color --bold red 95 | echo -n " [✘]" 96 | set_color normal 97 | set_color --bold 98 | set_color normal 99 | ) = (__sf_section_git_status) 100 | end 101 | 102 | test "Displays the correct symbol for stashed file" 103 | ( 104 | touch testfile 105 | command git add testfile 106 | command git commit -m "Initial commit" --quiet 107 | echo "modification" > testfile 108 | command git stash --quiet 109 | 110 | set_color --bold 111 | set_color normal 112 | set_color --bold red 113 | echo -n " [\$]" 114 | set_color normal 115 | set_color --bold 116 | set_color normal 117 | ) = (__sf_section_git_status) 118 | end 119 | 120 | test "Test config option SPACEFISH_GIT_STATUS_SHOW" 121 | ( 122 | set -g SPACEFISH_GIT_STATUS_SHOW false 123 | ) = (__sf_section_git_status) 124 | end 125 | 126 | # TODO: Get test dir into status *U* 127 | # TODO: Add test for ahead 128 | # TODO: Add test for behind 129 | # TODO: Add test for diverged 130 | -------------------------------------------------------------------------------- /docs/Troubleshooting.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | This page aimed to help you fix common problems encountered while using spacefish. 4 | 5 | ## My prompt is filling with errors 6 | 7 | Try all of the following troubleshooting steps: 8 | 9 | * Verify that your fish installation is at the [latest version](https://github.com/fish-shell/fish-shell/releases) 10 | 11 | ```sh 12 | fish --version 13 | ``` 14 | 15 | * Update spacefish with `fisher` or `omf` 16 | 17 | ```sh 18 | fisher add matchai/spacefish 19 | # or 20 | omf update spacefish 21 | ``` 22 | 23 | * If errors persist, please [open an issue](https://github.com/matchai/spacefish/issues/new) 24 | 25 | ## What's the weird symbol beside the `git` branch? 26 | 27 | You need to have a powerline patched font in order to properly display `git` branch symbol. 28 | 29 | * Install any powerline compatible font like [Fira Code](https://github.com/tonsky/FiraCode) or [others](https://github.com/powerline/fonts). 30 | * Configure your terminal emulator to [use that font](https://powerline.readthedocs.io/en/master/troubleshooting/osx.html). 31 | 32 | ## What's the weird character in front of a section? 33 | 34 | This is not an issue with spacefish. Spacefish uses Unicode symbols to represent `SPACESFISH_*_SYMBOL` in sections. To solve this problem: 35 | 36 | * Verify your terminal emulator supports Unicode characters with this command: 37 | 38 | ```sh 39 | curl https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt 40 | # or 41 | wget -O - https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt 42 | ``` 43 | * Configure your terminal emulator to use UTF-8 character encoding. 44 | 45 | 46 | In the event that Unicode characters aren't supported, you can replace them with characters that are compatible with your terminal with `SPACEFISH_*_SYMBOL` options. Check out the [Options](./docs/Options.md) page for more information. 47 | 48 | ## Why is my prompt slow? 49 | 50 | Spacefish may run more slowlyin big repositories since the status checks add up to be expensive operations. 51 | 52 | To speed up your prompt, try to reduce the number of unused spacefish sections that are enabled. Spacefish only loads the sections mentioned in `SPACEFISH_PROMPT_ORDER`. If you think some sections might not be be useful to you, you can disable them by not including their names in the prompt order. 53 | 54 | ## Why do my section icons overlap each other? 55 | 56 | ![overlapping icons](../images/icon-overlap.png) 57 | 58 | This issue is due to how your terminal emulator renders Unicode 9 characters. To fix this issue: 59 | 60 | * Make sure terminal uses _Unicode Version 9 Widths_. 61 | 62 | In _iTerm_ follow these instructions: 63 | 64 | * Go _iTerm → Preferences… (⌘,) → Profiles → Text_ 65 | * Check _Unicode Version 9 Widths_. 66 | * Reload your terminal's tab. 67 | 68 | ## Why doesn't my prompt look like it does in the preview? 69 | 70 | ![preview](../images/preview.gif) 71 | 72 | Preview shows a `spacefish` setup with: 73 | 74 | * [Hyper](https://hyper.is) as the terminal emulator. 75 | * [One Dark](https://www.npmjs.com/package/hyperterm-atom-dark) color theme from [Atom](https://atom.io/) editor. 76 | * [Fira Code](https://github.com/tonsky/FiraCode) with with ligatures as primary font (16px size). 77 | 78 | ## My problem wasn't solved 79 | 80 | If the above suggestions don't address your problem, feel free to [open an issue](https://github.com/matchai/spacefish/issues/new), describe your problem and we will gladly help you. 81 | -------------------------------------------------------------------------------- /functions/__sf_section_git_status.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Git status 3 | # 4 | 5 | function __sf_section_git_status -d "Display the current git status" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | __sf_util_set_default SPACEFISH_GIT_STATUS_SHOW true 11 | __sf_util_set_default SPACEFISH_GIT_STATUS_PREFIX " [" 12 | __sf_util_set_default SPACEFISH_GIT_STATUS_SUFFIX ] 13 | __sf_util_set_default SPACEFISH_GIT_STATUS_COLOR red 14 | __sf_util_set_default SPACEFISH_GIT_STATUS_UNTRACKED \? 15 | __sf_util_set_default SPACEFISH_GIT_STATUS_ADDED + 16 | __sf_util_set_default SPACEFISH_GIT_STATUS_MODIFIED ! 17 | __sf_util_set_default SPACEFISH_GIT_STATUS_RENAMED » 18 | __sf_util_set_default SPACEFISH_GIT_STATUS_DELETED ✘ 19 | __sf_util_set_default SPACEFISH_GIT_STATUS_STASHED \$ 20 | __sf_util_set_default SPACEFISH_GIT_STATUS_UNMERGED = 21 | __sf_util_set_default SPACEFISH_GIT_STATUS_AHEAD ⇡ 22 | __sf_util_set_default SPACEFISH_GIT_STATUS_BEHIND ⇣ 23 | __sf_util_set_default SPACEFISH_GIT_STATUS_DIVERGED ⇕ 24 | __sf_util_set_default SPACEFISH_GIT_PROMPT_ORDER untracked added modified renamed deleted stashed unmerged diverged ahead behind 25 | 26 | # ------------------------------------------------------------------------------ 27 | # Section 28 | # ------------------------------------------------------------------------------ 29 | 30 | [ $SPACEFISH_GIT_STATUS_SHOW = false ]; and return 31 | 32 | set -l git_status 33 | set -l is_ahead 34 | set -l is_behind 35 | 36 | set -l index (command git status --porcelain 2>/dev/null -b) 37 | set -l trimmed_index (string split \n $index | string sub --start 1 --length 2) 38 | 39 | for i in $trimmed_index 40 | if test (string match '\?\?' $i) 41 | set git_status untracked $git_status 42 | end 43 | if test (string match '*A*' $i) 44 | set git_status added $git_status 45 | end 46 | if test (string match '*M*' $i) 47 | set git_status modified $git_status 48 | end 49 | if test (string match '*R*' $i) 50 | set git_status renamed $git_status 51 | end 52 | if test (string match '*D*' $i) 53 | set git_status deleted $git_status 54 | end 55 | if test (string match '*U*' $i) 56 | set git_status unmerged $git_status 57 | end 58 | end 59 | 60 | # Check for stashes 61 | if test -n (echo (command git rev-parse --verify refs/stash 2>/dev/null)) 62 | set git_status stashed $git_status 63 | end 64 | 65 | # Check whether the branch is ahead 66 | if test (string match '*ahead*' $index) 67 | set is_ahead true 68 | end 69 | 70 | # Check whether the branch is behind 71 | if test (string match '*behind*' $index) 72 | set is_behind true 73 | end 74 | 75 | # Check whether the branch has diverged 76 | if test "$is_ahead" = "true" -a "$is_behind" = "true" 77 | set git_status diverged $git_status 78 | else if test "$is_ahead" = "true" 79 | set git_status ahead $git_status 80 | else if test "$is_behind" = "true" 81 | set git_status behind $git_status 82 | end 83 | 84 | set -l full_git_status 85 | for i in $SPACEFISH_GIT_PROMPT_ORDER 86 | set i (string upper $i) 87 | set git_status (string upper $git_status) 88 | if contains $i in $git_status 89 | set -l status_symbol SPACEFISH_GIT_STATUS_$i 90 | set full_git_status "$$status_symbol$full_git_status" 91 | end 92 | end 93 | 94 | # Check if git status 95 | if test -n "$full_git_status" 96 | __sf_lib_section \ 97 | $SPACEFISH_GIT_STATUS_COLOR \ 98 | "$SPACEFISH_GIT_STATUS_PREFIX$full_git_status$SPACEFISH_GIT_STATUS_SUFFIX" 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /tests/__sf_section_vi_mode.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | fish_vi_key_bindings; or true 6 | # Unfortunately right after enabling vi-keys it's in 'normal' state on CI and in 'insert' locally 7 | set fish_bind_mode insert 8 | end 9 | 10 | test "Prints section when fish_vi_key_bindigs is set" 11 | ( 12 | set_color --bold 13 | echo -n " " 14 | set_color normal 15 | set_color --bold white 16 | echo -n "[I]" 17 | set_color normal 18 | set_color --bold 19 | echo -n " " 20 | set_color normal 21 | ) = (__sf_section_vi_mode) 22 | end 23 | 24 | test "Prints SPACEFISH_VI_MODE_VISUAL when fish_bind_mode is visual" 25 | ( 26 | set fish_bind_mode visual 27 | set SPACEFISH_VI_MODE_VISUAL "-V-" 28 | 29 | set_color --bold 30 | echo -n " " 31 | set_color normal 32 | set_color --bold white 33 | echo -n $SPACEFISH_VI_MODE_VISUAL 34 | set_color normal 35 | set_color --bold 36 | echo -n " " 37 | set_color normal 38 | ) = (__sf_section_vi_mode) 39 | end 40 | 41 | test "Prints SPACEFISH_VI_MODE_REPLACE_ONE when fish_bind_mode is replace_one" 42 | ( 43 | set fish_bind_mode replace_one 44 | set SPACEFISH_VI_MODE_REPLACE_ONE "-R-" 45 | 46 | set_color --bold 47 | echo -n " " 48 | set_color normal 49 | set_color --bold white 50 | echo -n $SPACEFISH_VI_MODE_REPLACE_ONE 51 | set_color normal 52 | set_color --bold 53 | echo -n " " 54 | set_color normal 55 | ) = (__sf_section_vi_mode) 56 | end 57 | 58 | test "Prints SPACEFISH_VI_MODE_NORMAL when fish_bind_mode is normal" 59 | ( 60 | set fish_bind_mode default 61 | set SPACEFISH_VI_MODE_NORMAL "-N-" 62 | 63 | set_color --bold 64 | echo -n " " 65 | set_color normal 66 | set_color --bold white 67 | echo -n $SPACEFISH_VI_MODE_NORMAL 68 | set_color normal 69 | set_color --bold 70 | echo -n " " 71 | set_color normal 72 | ) = (__sf_section_vi_mode) 73 | end 74 | 75 | test "Prints SPACEFISH_VI_MODE_INSERT when fish_bind_mode is insert" 76 | ( 77 | set fish_bind_mode insert 78 | set SPACEFISH_VI_MODE_INSERT "-I-" 79 | 80 | set_color --bold 81 | echo -n " " 82 | set_color normal 83 | set_color --bold white 84 | echo -n $SPACEFISH_VI_MODE_INSERT 85 | set_color normal 86 | set_color --bold 87 | echo -n " " 88 | set_color normal 89 | ) = (__sf_section_vi_mode) 90 | end 91 | 92 | test "Prints prefix when SPACEFISH_VI_MODE_PREFIX is set" 93 | ( 94 | set SPACEFISH_VI_MODE_PREFIX "VIM " 95 | 96 | set_color --bold 97 | echo -n "$SPACEFISH_VI_MODE_PREFIX" 98 | set_color normal 99 | set_color --bold white 100 | echo -n "[I]" 101 | set_color normal 102 | set_color --bold 103 | echo -n " " 104 | set_color normal 105 | ) = (__sf_section_vi_mode) 106 | end 107 | 108 | test "Prints suffix when SPACEFISH_VI_MODE_SUFFIX is set" 109 | ( 110 | set SPACEFISH_VI_MODE_SUFFIX " VIM " 111 | 112 | set_color --bold 113 | echo -n " " 114 | set_color normal 115 | set_color --bold white 116 | echo -n "[I]" 117 | set_color normal 118 | set_color --bold 119 | echo -n $SPACEFISH_VI_MODE_SUFFIX 120 | set_color normal 121 | ) = (__sf_section_vi_mode) 122 | end 123 | 124 | test "Use color from SPACEFISH_VI_MODE_COLOR" 125 | ( 126 | set SPACEFISH_VI_MODE_COLOR red 127 | 128 | set_color --bold 129 | echo -n " " 130 | set_color normal 131 | set_color --bold red 132 | echo -n "[I]" 133 | set_color normal 134 | set_color --bold 135 | echo -n " " 136 | set_color normal 137 | ) = (__sf_section_vi_mode) 138 | end 139 | 140 | test "Don't print anything if SPACEFISH_VI_MODE_SHOW is false" 141 | ( 142 | set SPACEFISH_VI_MODE_SHOW false 143 | ) = (__sf_section_vi_mode) 144 | end 145 | -------------------------------------------------------------------------------- /tests/__sf_section_pyenv.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock pyenv version-name 0 "echo \"3.7.0\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | if test "$PYENV_VERSION" 13 | set -e PYENV_VERSION 14 | end 15 | end 16 | 17 | test "Prints section when \$PYENV_VERSION is defined" 18 | ( 19 | set PYENV_VERSION 3.7.0 20 | 21 | set_color --bold 22 | echo -n "via " 23 | set_color normal 24 | set_color --bold yellow 25 | echo -n "🐍 3.7.0" 26 | set_color normal 27 | set_color --bold 28 | echo -n " " 29 | set_color normal 30 | ) = (__sf_section_pyenv) 31 | end 32 | 33 | test "Prints section when .python-version is present" 34 | ( 35 | touch /tmp/tmp-spacefish/.python-version 36 | 37 | set_color --bold 38 | echo -n "via " 39 | set_color normal 40 | set_color --bold yellow 41 | echo -n "🐍 3.7.0" 42 | set_color normal 43 | set_color --bold 44 | echo -n " " 45 | set_color normal 46 | ) = (__sf_section_pyenv) 47 | end 48 | 49 | test "Prints section when requirements.txt is present" 50 | ( 51 | touch /tmp/tmp-spacefish/requirements.txt 52 | 53 | set_color --bold 54 | echo -n "via " 55 | set_color normal 56 | set_color --bold yellow 57 | echo -n "🐍 3.7.0" 58 | set_color normal 59 | set_color --bold 60 | echo -n " " 61 | set_color normal 62 | ) = (__sf_section_pyenv) 63 | end 64 | 65 | test "Prints section when pyproject.toml is present" 66 | ( 67 | touch /tmp/tmp-spacefish/pyproject.toml 68 | 69 | set_color --bold 70 | echo -n "via " 71 | set_color normal 72 | set_color --bold yellow 73 | echo -n "🐍 3.7.0" 74 | set_color normal 75 | set_color --bold 76 | echo -n " " 77 | set_color normal 78 | ) = (__sf_section_pyenv) 79 | end 80 | 81 | test "Prints section when a *.py file is present" 82 | ( 83 | touch /tmp/tmp-spacefish/testfile.py 84 | 85 | set_color --bold 86 | echo -n "via " 87 | set_color normal 88 | set_color --bold yellow 89 | echo -n "🐍 3.7.0" 90 | set_color normal 91 | set_color --bold 92 | echo -n " " 93 | set_color normal 94 | ) = (__sf_section_pyenv) 95 | end 96 | 97 | test "Doesn't print the section when requirements.txt and *.py aren't present" 98 | () = (__sf_section_pyenv) 99 | end 100 | 101 | test "Changing SPACEFISH_PYENV_SYMBOL changes the displayed character" 102 | ( 103 | touch /tmp/tmp-spacefish/requirements.txt 104 | set SPACEFISH_PYENV_SYMBOL "· " 105 | 106 | set_color --bold 107 | echo -n "via " 108 | set_color normal 109 | set_color --bold yellow 110 | echo -n "· 3.7.0" 111 | set_color normal 112 | set_color --bold 113 | echo -n " " 114 | set_color normal 115 | ) = (__sf_section_pyenv) 116 | end 117 | 118 | test "Changing SPACEFISH_PYENV_PREFIX changes the character prefix" 119 | ( 120 | touch /tmp/tmp-spacefish/requirements.txt 121 | set sf_exit_code 0 122 | set SPACEFISH_PYENV_PREFIX · 123 | 124 | set_color --bold 125 | echo -n "·" 126 | set_color normal 127 | set_color --bold yellow 128 | echo -n "🐍 3.7.0" 129 | set_color normal 130 | set_color --bold 131 | echo -n " " 132 | set_color normal 133 | ) = (__sf_section_pyenv) 134 | end 135 | 136 | test "Changing SPACEFISH_PYENV_SUFFIX changes the character suffix" 137 | ( 138 | touch /tmp/tmp-spacefish/requirements.txt 139 | set sf_exit_code 0 140 | set SPACEFISH_PYENV_SUFFIX · 141 | 142 | set_color --bold 143 | echo -n "via " 144 | set_color normal 145 | set_color --bold yellow 146 | echo -n "🐍 3.7.0" 147 | set_color normal 148 | set_color --bold 149 | echo -n "·" 150 | set_color normal 151 | ) = (__sf_section_pyenv) 152 | end 153 | 154 | test "doesn't display the section when SPACEFISH_PYENV_SHOW is set to \"false\"" 155 | ( 156 | touch /tmp/tmp-spacefish/requirements.txt 157 | set SPACEFISH_PYENV_SHOW false 158 | ) = (__sf_section_pyenv) 159 | end 160 | -------------------------------------------------------------------------------- /tests/__sf_section_golang.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock go version 0 "echo \"go version go1.10.3 darwin/amd64\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints section when Godeps is present" 15 | ( 16 | mkdir /tmp/tmp-spacefish/Godeps 17 | 18 | set_color --bold 19 | echo -n "via " 20 | set_color normal 21 | set_color --bold cyan 22 | echo -n "🐹 v1.10.3" 23 | set_color normal 24 | set_color --bold 25 | echo -n " " 26 | set_color normal 27 | ) = (__sf_section_golang) 28 | end 29 | 30 | test "Prints section when glide.yaml is present" 31 | ( 32 | touch /tmp/tmp-spacefish/glide.yaml 33 | 34 | set_color --bold 35 | echo -n "via " 36 | set_color normal 37 | set_color --bold cyan 38 | echo -n "🐹 v1.10.3" 39 | set_color normal 40 | set_color --bold 41 | echo -n " " 42 | set_color normal 43 | ) = (__sf_section_golang) 44 | end 45 | 46 | test "Prints section when Gopkg.yml is present" 47 | ( 48 | touch /tmp/tmp-spacefish/Gopkg.yml 49 | 50 | set_color --bold 51 | echo -n "via " 52 | set_color normal 53 | set_color --bold cyan 54 | echo -n "🐹 v1.10.3" 55 | set_color normal 56 | set_color --bold 57 | echo -n " " 58 | set_color normal 59 | ) = (__sf_section_golang) 60 | end 61 | 62 | test "Prints section when Gopkg.lock is present" 63 | ( 64 | touch /tmp/tmp-spacefish/Gopkg.lock 65 | 66 | set_color --bold 67 | echo -n "via " 68 | set_color normal 69 | set_color --bold cyan 70 | echo -n "🐹 v1.10.3" 71 | set_color normal 72 | set_color --bold 73 | echo -n " " 74 | set_color normal 75 | ) = (__sf_section_golang) 76 | end 77 | 78 | test "Prints section when go.mod is present" 79 | ( 80 | touch /tmp/tmp-spacefish/go.mod 81 | 82 | set_color --bold 83 | echo -n "via " 84 | set_color normal 85 | set_color --bold cyan 86 | echo -n "🐹 v1.10.3" 87 | set_color normal 88 | set_color --bold 89 | echo -n " " 90 | set_color normal 91 | ) = (__sf_section_golang) 92 | end 93 | 94 | test "Print section when using development version of golang" 95 | ( 96 | mock go version 0 "echo go version devel +5efe9a8f11 Wed Jan 9 07:21:16 2019 +0000 darwin/amd64" 97 | touch /tmp/tmp-spacefish/Gopkg.lock 98 | 99 | set_color --bold 100 | echo -n "via " 101 | set_color normal 102 | set_color --bold cyan 103 | echo -n "🐹 devel:5efe9a8f11" 104 | set_color normal 105 | set_color --bold 106 | echo -n " " 107 | set_color normal 108 | ) = (__sf_section_golang) 109 | end 110 | 111 | test "Doesn't print the section when golang files aren't present" 112 | () = (__sf_section_golang) 113 | end 114 | 115 | test "Changing SPACEFISH_GOLANG_SYMBOL changes the displayed character" 116 | ( 117 | touch /tmp/tmp-spacefish/Gopkg.lock 118 | set SPACEFISH_GOLANG_SYMBOL "· " 119 | 120 | set_color --bold 121 | echo -n "via " 122 | set_color normal 123 | set_color --bold cyan 124 | echo -n "· v1.10.3" 125 | set_color normal 126 | set_color --bold 127 | echo -n " " 128 | set_color normal 129 | ) = (__sf_section_golang) 130 | end 131 | 132 | test "Changing SPACEFISH_GOLANG_PREFIX changes the character prefix" 133 | ( 134 | touch /tmp/tmp-spacefish/Gopkg.lock 135 | set sf_exit_code 0 136 | set SPACEFISH_GOLANG_PREFIX · 137 | 138 | set_color --bold 139 | echo -n "·" 140 | set_color normal 141 | set_color --bold cyan 142 | echo -n "🐹 v1.10.3" 143 | set_color normal 144 | set_color --bold 145 | echo -n " " 146 | set_color normal 147 | ) = (__sf_section_golang) 148 | end 149 | 150 | test "Changing SPACEFISH_GOLANG_SUFFIX changes the character suffix" 151 | ( 152 | touch /tmp/tmp-spacefish/Gopkg.lock 153 | set sf_exit_code 0 154 | set SPACEFISH_GOLANG_SUFFIX · 155 | 156 | set_color --bold 157 | echo -n "via " 158 | set_color normal 159 | set_color --bold cyan 160 | echo -n "🐹 v1.10.3" 161 | set_color normal 162 | set_color --bold 163 | echo -n "·" 164 | set_color normal 165 | ) = (__sf_section_golang) 166 | end 167 | 168 | test "doesn't display the section when SPACEFISH_GOLANG_SHOW is set to \"false\"" 169 | ( 170 | touch /tmp/tmp-spacefish/Gopkg.lock 171 | set SPACEFISH_GOLANG_SHOW false 172 | ) = (__sf_section_golang) 173 | end 174 | -------------------------------------------------------------------------------- /functions/__sf_section_battery.fish: -------------------------------------------------------------------------------- 1 | # 2 | # Battery 3 | # 4 | 5 | function __sf_section_battery -d "Displays battery symbol and charge" 6 | # ------------------------------------------------------------------------------ 7 | # Configuration 8 | # ------------------------------------------------------------------------------ 9 | 10 | # ------------------------------------------------------------------------------ 11 | # | SPACEFISH_BATTERY_SHOW | below threshold | above threshold | fully charged | 12 | # |------------------------+-----------------+-----------------+---------------| 13 | # | false | hidden | hidden | hidden | 14 | # | always | shown | shown | shown | 15 | # | true | shown | hidden | hidden | 16 | # | charged | shown | hidden | shown | 17 | # ------------------------------------------------------------------------------ 18 | 19 | __sf_util_set_default SPACEFISH_BATTERY_SHOW true 20 | __sf_util_set_default SPACEFISH_BATTERY_PREFIX "" 21 | __sf_util_set_default SPACEFISH_BATTERY_SUFFIX " " 22 | __sf_util_set_default SPACEFISH_BATTERY_SYMBOL_CHARGING ⇡ 23 | __sf_util_set_default SPACEFISH_BATTERY_SYMBOL_DISCHARGING ⇣ 24 | __sf_util_set_default SPACEFISH_BATTERY_SYMBOL_FULL • 25 | __sf_util_set_default SPACEFISH_BATTERY_THRESHOLD 10 26 | 27 | # ------------------------------------------------------------------------------ 28 | # Section 29 | # ------------------------------------------------------------------------------ 30 | 31 | # Show section only if any of the following is true 32 | # - SPACEFISH_BATTERY_SHOW = "always" 33 | # - SPACEFISH_BATTERY_SHOW = "true" and 34 | # - battery percentage is below the given limit (default: 10%) 35 | # - SPACEFISH_BATTERY_SHOW = "charged" and 36 | # - Battery is fully charged 37 | 38 | # Check that user wants to show battery levels 39 | [ $SPACEFISH_BATTERY_SHOW = false ]; and return 40 | 41 | set -l battery_data 42 | set -l battery_percent 43 | set -l battery_status 44 | set -l battery_color 45 | set -l battery_symbol 46 | 47 | # Darwin and macOS machines 48 | if type -q pmset 49 | set battery_data (pmset -g batt | grep "InternalBattery") 50 | 51 | # Return if no internal battery 52 | if test -z (echo $battery_data) 53 | return 54 | end 55 | 56 | set battery_percent (echo $battery_data | grep -oE "[0-9]{1,3}%") 57 | # spaceship has echo $battery_data | awk -F '; *' 'NR==2 { print $2 }', but NR==2 did not return anything. 58 | set battery_status (echo $battery_data | awk -F '; *' '{ print $2 }') 59 | 60 | # Linux machines 61 | else if type -q upower 62 | set -l battery (upower -e | grep battery | head -1) 63 | 64 | [ -z $battery ]; and return 65 | 66 | set -l IFS # Clear IFS to allow for multi-line variables 67 | set battery_data (upower -i $battery) 68 | set battery_percent (echo $battery_data | grep percentage | awk '{print $2}') 69 | set battery_status (echo $battery_data | grep state | awk '{print $2}') 70 | 71 | # Windows machines. 72 | else if type -q acpi 73 | set -l battery_data (acpi -b 2>/dev/null | head -1) 74 | 75 | # Return if no battery 76 | [ -z $battery_data ]; and return 77 | 78 | set battery_percent ( echo $battery_data | awk '{print $4}' ) 79 | set battery_status ( echo $battery_data | awk '{print tolower($3)}' ) 80 | else 81 | return 82 | end 83 | 84 | # Remove trailing % and symbols for comparison 85 | set battery_percent (echo $battery_percent | string trim --chars=%[,;]) 86 | 87 | if test "$battery_percent" -eq 100 -o -n (echo (string match -r "(charged|full)" $battery_status)) 88 | set battery_color green 89 | else if test "$battery_percent" -lt "$SPACEFISH_BATTERY_THRESHOLD" 90 | set battery_color red 91 | else 92 | set battery_color yellow 93 | end 94 | 95 | # Battery indicator based on current status of battery 96 | if test "$battery_status" = "charging" 97 | set battery_symbol $SPACEFISH_BATTERY_SYMBOL_CHARGING 98 | else if test -n (echo (string match -r "^[dD]ischarg.*" $battery_status)) 99 | set battery_symbol $SPACEFISH_BATTERY_SYMBOL_DISCHARGING 100 | else 101 | set battery_symbol $SPACEFISH_BATTERY_SYMBOL_FULL 102 | end 103 | 104 | if test "$SPACEFISH_BATTERY_SHOW" = "always" \ 105 | -o "$battery_percent" -lt "$SPACEFISH_BATTERY_THRESHOLD" \ 106 | -o "$SPACEFISH_BATTERY_SHOW" = "charged" \ 107 | -a -n (echo (string match -r "(charged|full)" $battery_status)) 108 | __sf_lib_section \ 109 | $battery_color \ 110 | $SPACEFISH_BATTERY_PREFIX \ 111 | "$battery_symbol$battery_percent%" \ 112 | $SPACEFISH_BATTERY_SUFFIX 113 | end 114 | end 115 | -------------------------------------------------------------------------------- /tests/__sf_section_dotnet.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock dotnet --version 0 "echo \"2.1.403\"" 6 | mkdir -p /tmp/tmp-spacefish 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints nothing when required files are missing" 15 | ( 16 | rm -f /tmp/tmp-spacefish/project.json 17 | rm -f /tmp/tmp-spacefish/global.json 18 | rm -f /tmp/tmp-spacefish/paket.dependencies 19 | rm -f '/tmp/tmp-spacefish/*.sln' 20 | rm -f '/tmp/tmp-spacefish/*.csproj' 21 | rm -f '/tmp/tmp-spacefish/*.fsproj' 22 | rm -f '/tmp/tmp-spacefish/*.xproj' 23 | ) = (__sf_section_dotnet) 24 | end 25 | 26 | test "Prints section if project.json is present" 27 | ( 28 | touch /tmp/tmp-spacefish/project.json 29 | 30 | set_color --bold 31 | echo -n "via " 32 | set_color normal 33 | set_color --bold af00d7 34 | echo -n ".NET 2.1.403" 35 | set_color normal 36 | set_color --bold 37 | echo -n " " 38 | set_color normal 39 | ) = (__sf_section_dotnet) 40 | end 41 | 42 | test "Prints section if global.json is present" 43 | ( 44 | touch /tmp/tmp-spacefish/global.json 45 | set_color --bold 46 | 47 | echo -n "via " 48 | set_color normal 49 | set_color --bold af00d7 50 | echo -n ".NET 2.1.403" 51 | set_color normal 52 | set_color --bold 53 | echo -n " " 54 | set_color normal 55 | ) = (__sf_section_dotnet) 56 | end 57 | 58 | test "Prints section if paket.dependencies is present" 59 | ( 60 | touch /tmp/tmp-spacefish/paket.dependencies 61 | set_color --bold 62 | 63 | echo -n "via " 64 | set_color normal 65 | set_color --bold af00d7 66 | echo -n ".NET 2.1.403" 67 | set_color normal 68 | set_color --bold 69 | echo -n " " 70 | set_color normal 71 | ) = (__sf_section_dotnet) 72 | end 73 | 74 | test "Prints section if a .csproj file is present" 75 | ( 76 | touch /tmp/tmp-spacefish/tmp.csproj 77 | 78 | set_color --bold 79 | echo -n "via " 80 | set_color normal 81 | set_color --bold af00d7 82 | echo -n ".NET 2.1.403" 83 | set_color normal 84 | set_color --bold 85 | echo -n " " 86 | set_color normal 87 | ) = (__sf_section_dotnet) 88 | end 89 | 90 | test "Prints section if a .fsproj file is present" 91 | ( 92 | touch /tmp/tmp-spacefish/tmp.fsproj 93 | 94 | set_color --bold 95 | echo -n "via " 96 | set_color normal 97 | set_color --bold af00d7 98 | echo -n ".NET 2.1.403" 99 | set_color normal 100 | set_color --bold 101 | echo -n " " 102 | set_color normal 103 | ) = (__sf_section_dotnet) 104 | end 105 | 106 | test "Prints section if a .xproj file is present" 107 | ( 108 | touch /tmp/tmp-spacefish/tmp.xproj 109 | set_color --bold 110 | 111 | echo -n "via " 112 | set_color normal 113 | set_color --bold af00d7 114 | echo -n ".NET 2.1.403" 115 | set_color normal 116 | set_color --bold 117 | echo -n " " 118 | set_color normal 119 | ) = (__sf_section_dotnet) 120 | end 121 | 122 | test "Prints section if a .sln file is present" 123 | ( 124 | touch /tmp/tmp-spacefish/tmp.sln 125 | 126 | set_color --bold 127 | echo -n "via " 128 | set_color normal 129 | set_color --bold af00d7 130 | echo -n ".NET 2.1.403" 131 | set_color normal 132 | set_color --bold 133 | echo -n " " 134 | set_color normal 135 | ) = (__sf_section_dotnet) 136 | end 137 | 138 | test "Changing SPACEFISH_DOTNET_SYMBOL changes the displayed character" 139 | ( 140 | touch /tmp/tmp-spacefish/tmp.sln 141 | 142 | set SPACEFISH_DOTNET_SYMBOL "· " 143 | set_color --bold 144 | echo -n "via " 145 | set_color normal 146 | set_color --bold af00d7 147 | echo -n "· 2.1.403" 148 | set_color normal 149 | set_color --bold 150 | echo -n " " 151 | set_color normal 152 | ) = (__sf_section_dotnet) 153 | end 154 | 155 | test "Changing SPACEFISH_DOTNET_PREFIX changes the character prefix" 156 | ( 157 | touch /tmp/tmp-spacefish/tmp.sln 158 | set sf_exit_code 0 159 | set SPACEFISH_DOTNET_PREFIX · 160 | 161 | set_color --bold 162 | echo -n "·" 163 | set_color normal 164 | set_color --bold af00d7 165 | echo -n ".NET 2.1.403" 166 | set_color normal 167 | set_color --bold 168 | echo -n " " 169 | set_color normal 170 | ) = (__sf_section_dotnet) 171 | end 172 | 173 | test "Changing SPACEFISH_DOTNET_SUFFIX changes the character prefix" 174 | ( 175 | touch /tmp/tmp-spacefish/tmp.sln 176 | set sf_exit_code 0 177 | set SPACEFISH_DOTNET_SUFFIX · 178 | 179 | set_color --bold 180 | echo -n "via " 181 | set_color normal 182 | set_color --bold af00d7 183 | echo -n ".NET 2.1.403" 184 | set_color normal 185 | set_color --bold 186 | echo -n "·" 187 | set_color normal 188 | ) = (__sf_section_dotnet) 189 | end 190 | 191 | test "Doesn't display .NET when SPACEFISH_DOTNET_SHOW is set to 'false'" 192 | ( 193 | set SPACEFISH_DOTNET_SHOW false 194 | ) = (__sf_section_dotnet) 195 | end 196 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [2.7.0](https://github.com/matchai/spacefish/compare/v2.6.1...v2.7.0) (2019-08-21) 2 | 3 | 4 | ### Features 5 | 6 | * **aws:** Support aws-vault as an option instead of named AWS p… ([#206](https://github.com/matchai/spacefish/issues/206)) ([5e02e3f](https://github.com/matchai/spacefish/commit/5e02e3f)) 7 | 8 | ## [2.6.1](https://github.com/matchai/spacefish/compare/v2.6.0...v2.6.1) (2019-07-01) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * correct incorrectly named config options ([#198](https://github.com/matchai/spacefish/issues/198)) ([85f9ef5](https://github.com/matchai/spacefish/commit/85f9ef5)) 14 | 15 | # [2.6.0](https://github.com/matchai/spacefish/compare/v2.5.0...v2.6.0) (2019-06-19) 16 | 17 | 18 | ### Features 19 | 20 | * Add elixir section ([#190](https://github.com/matchai/spacefish/issues/190)) ([9cb48ea](https://github.com/matchai/spacefish/commit/9cb48ea)) 21 | 22 | # [2.5.0](https://github.com/matchai/spacefish/compare/v2.4.0...v2.5.0) (2019-05-23) 23 | 24 | 25 | ### Features 26 | 27 | * bump version ([13865c6](https://github.com/matchai/spacefish/commit/13865c6)) 28 | 29 | # [2.4.0](https://github.com/matchai/spacefish/compare/v2.3.1...v2.4.0) (2019-03-08) 30 | 31 | 32 | ### Features 33 | 34 | * add cargo package manager and refactor existing package section ([#171](https://github.com/matchai/spacefish/issues/171)) ([0064d2d](https://github.com/matchai/spacefish/commit/0064d2d)) 35 | 36 | ## [2.3.1](https://github.com/matchai/spacefish/compare/v2.3.0...v2.3.1) (2019-03-02) 37 | 38 | 39 | ### Bug Fixes 40 | 41 | * correct typo in venv configuration variables ([#167](https://github.com/matchai/spacefish/issues/167)) ([8a3585c](https://github.com/matchai/spacefish/commit/8a3585c)) 42 | 43 | # [2.3.0](https://github.com/matchai/spacefish/compare/v2.2.4...v2.3.0) (2019-02-24) 44 | 45 | 46 | ### Features 47 | 48 | * add Python venv section ([#164](https://github.com/matchai/spacefish/issues/164)) ([3d777fc](https://github.com/matchai/spacefish/commit/3d777fc)), closes [#146](https://github.com/matchai/spacefish/issues/146) 49 | 50 | ## [2.2.4](https://github.com/matchai/spacefish/compare/v2.2.3...v2.2.4) (2019-02-17) 51 | 52 | 53 | ### Bug Fixes 54 | 55 | * don't throw errors when there are multiple GOPATHs ([#158](https://github.com/matchai/spacefish/issues/158)) ([653f1c8](https://github.com/matchai/spacefish/commit/653f1c8)) 56 | 57 | ## [2.2.3](https://github.com/matchai/spacefish/compare/v2.2.2...v2.2.3) (2019-02-17) 58 | 59 | 60 | ### Bug Fixes 61 | 62 | * git status section shows the correct symbol for unmerged ([#159](https://github.com/matchai/spacefish/issues/159)) ([7c2a1d5](https://github.com/matchai/spacefish/commit/7c2a1d5)) 63 | 64 | ## [2.2.2](https://github.com/matchai/spacefish/compare/v2.2.1...v2.2.2) (2019-02-14) 65 | 66 | 67 | ### Bug Fixes 68 | 69 | * show git status based on SPACEFISH_GIT_STATUS_SHOW ([#155](https://github.com/matchai/spacefish/issues/155)) ([1d34eb9](https://github.com/matchai/spacefish/commit/1d34eb9)) 70 | 71 | ## [2.2.1](https://github.com/matchai/spacefish/compare/v2.2.0...v2.2.1) (2019-02-14) 72 | 73 | 74 | ### Bug Fixes 75 | 76 | * use SPACEFISH_TIME_FORMAT when formatting time section ([#156](https://github.com/matchai/spacefish/issues/156)) ([6ab4ecc](https://github.com/matchai/spacefish/commit/6ab4ecc)) 77 | 78 | # [2.2.0](https://github.com/matchai/spacefish/compare/v2.1.0...v2.2.0) (2019-02-02) 79 | 80 | 81 | ### Features 82 | 83 | * add support for F# project detection in the dotnet section ([c104b04](https://github.com/matchai/spacefish/commit/c104b04)) 84 | 85 | # [2.1.0](https://github.com/matchai/spacefish/compare/v2.0.1...v2.1.0) (2019-01-23) 86 | 87 | 88 | ### Bug Fixes 89 | 90 | * correct go development version format ([e678ac2](https://github.com/matchai/spacefish/commit/e678ac2)), closes [#137](https://github.com/matchai/spacefish/issues/137) 91 | 92 | 93 | ### Features 94 | 95 | * improve pyenv version detection ([22b9e20](https://github.com/matchai/spacefish/commit/22b9e20)), closes [#140](https://github.com/matchai/spacefish/issues/140) 96 | * provide docker version if in a docker container ([62891b4](https://github.com/matchai/spacefish/commit/62891b4)), closes [#138](https://github.com/matchai/spacefish/issues/138) 97 | 98 | ## [2.0.1](https://github.com/matchai/spacefish/compare/v2.0.0...v2.0.1) (2019-01-09) 99 | 100 | 101 | ### Bug Fixes 102 | 103 | * have ACPI use only the first battery value ([#126](https://github.com/matchai/spacefish/issues/126)) ([8fa713b](https://github.com/matchai/spacefish/commit/8fa713b)) 104 | 105 | # [2.0.0](https://github.com/matchai/spacefish/compare/v1.12.4...v2.0.0) (2019-01-09) 106 | 107 | 108 | ### Bug Fixes 109 | 110 | * remove color from prefix/suffix ([#133](https://github.com/matchai/spacefish/issues/133)) ([319f0b0](https://github.com/matchai/spacefish/commit/319f0b0)) 111 | 112 | 113 | ### BREAKING CHANGES 114 | 115 | * Because prefix and suffix colors are no longer set to #fff, the color of prefix and suffix will be set to the default foreground color of your shell. 116 | -------------------------------------------------------------------------------- /tests/__sf_section_node.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mock node -v 0 "echo \"v9.8.0\"" 6 | mkdir -p /tmp/tmp-spacefish/ 7 | cd /tmp/tmp-spacefish 8 | end 9 | 10 | function teardown 11 | rm -rf /tmp/tmp-spacefish 12 | end 13 | 14 | test "Prints section when node_modules is present" 15 | ( 16 | mkdir /tmp/tmp-spacefish/node_modules 17 | 18 | set_color --bold 19 | echo -n "via " 20 | set_color normal 21 | set_color --bold green 22 | echo -n "⬢ v9.8.0" 23 | set_color normal 24 | set_color --bold 25 | echo -n " " 26 | set_color normal 27 | ) = (__sf_section_node) 28 | end 29 | 30 | test "Prints section when package.json is present" 31 | ( 32 | touch /tmp/tmp-spacefish/package.json 33 | 34 | set_color --bold 35 | echo -n "via " 36 | set_color normal 37 | set_color --bold green 38 | echo -n "⬢ v9.8.0" 39 | set_color normal 40 | set_color --bold 41 | echo -n " " 42 | set_color normal 43 | ) = (__sf_section_node) 44 | end 45 | 46 | test "Doesn't print section when not in a directory with node_modules or package.json" 47 | () = (__sf_section_node) 48 | end 49 | 50 | test "Prints nvm version when nvm is installed" 51 | ( 52 | mkdir /tmp/tmp-spacefish/node_modules 53 | set -e sf_node_version 54 | mock nvm current 0 "echo \"v9.8.0\"" 55 | 56 | set_color --bold 57 | echo -n "via " 58 | set_color normal 59 | set_color --bold green 60 | echo -n "⬢ v9.8.0" 61 | set_color normal 62 | set_color --bold 63 | echo -n " " 64 | set_color normal 65 | ) = (__sf_section_node) 66 | end 67 | 68 | test "Prints cached nvm version if previously used" 69 | ( 70 | mkdir /tmp/tmp-spacefish/node_modules 71 | set sf_node_version "v1.2.3" 72 | set sf_last_nvm_bin "path_to_bin" 73 | set NVM_BIN "path_to_bin" 74 | mock nvm current 0 75 | 76 | set_color --bold 77 | echo -n "via " 78 | set_color normal 79 | set_color --bold green 80 | echo -n "⬢ v1.2.3" 81 | set_color normal 82 | set_color --bold 83 | echo -n " " 84 | set_color normal 85 | ) = (__sf_section_node) 86 | end 87 | 88 | test "Prints nodenv version when nodenv is installed" 89 | ( 90 | mkdir /tmp/tmp-spacefish/node_modules 91 | mock nodenv version-name 0 "echo \"v9.8.0\"" 92 | 93 | set_color --bold 94 | echo -n "via " 95 | set_color normal 96 | set_color --bold green 97 | echo -n "⬢ v9.8.0" 98 | set_color normal 99 | set_color --bold 100 | echo -n " " 101 | set_color normal 102 | ) = (__sf_section_node) 103 | 104 | test "Prints nothing when using the \"system\" version of node with nvm" 105 | ( 106 | mkdir -p /tmp/tmp-spacefish/node_modules 107 | mock nvm current 0 "echo \"system\"" 108 | ) = (__sf_section_node) 109 | end 110 | 111 | test "Prints nothing when using the \"system\" version of node with nodenv" 112 | ( 113 | mkdir /tmp/tmp-spacefish/node_modules 114 | mock nodenv version-name 0 "echo \"system\"" 115 | ) = (__sf_section_node) 116 | end 117 | 118 | test "Prints nodenv version when nodenv is installed" 119 | ( 120 | mkdir /tmp/tmp-spacefish/node_modules 121 | mock nodenv version-name 0 "echo \"node\"" 122 | ) = (__sf_section_node) 123 | end 124 | 125 | test "Changing SPACEFISH_NODE_SYMBOL changes the displayed character" 126 | ( 127 | mkdir /tmp/tmp-spacefish/node_modules 128 | mock nvm current 0 "echo \"v9.8.0\"" 129 | set SPACEFISH_NODE_SYMBOL "· " 130 | 131 | set_color --bold 132 | echo -n "via " 133 | set_color normal 134 | set_color --bold green 135 | echo -n "· v9.8.0" 136 | set_color normal 137 | set_color --bold 138 | echo -n " " 139 | set_color normal 140 | ) = (__sf_section_node) 141 | end 142 | 143 | test "Changing SPACEFISH_NODE_PREFIX changes the character prefix" 144 | ( 145 | mkdir /tmp/tmp-spacefish/node_modules 146 | set sf_exit_code 0 147 | set SPACEFISH_NODE_PREFIX · 148 | 149 | set_color --bold 150 | echo -n "·" 151 | set_color normal 152 | set_color --bold green 153 | echo -n "⬢ v9.8.0" 154 | set_color normal 155 | set_color --bold 156 | echo -n " " 157 | set_color normal 158 | ) = (__sf_section_node) 159 | end 160 | 161 | test "Changing SPACEFISH_NODE_PREFIX changes the character prefix" 162 | ( 163 | mkdir /tmp/tmp-spacefish/node_modules 164 | set sf_exit_code 0 165 | set SPACEFISH_NODE_SUFFIX · 166 | 167 | set_color --bold 168 | echo -n "via " 169 | set_color normal 170 | set_color --bold green 171 | echo -n "⬢ v9.8.0" 172 | set_color normal 173 | set_color --bold 174 | echo -n "·" 175 | set_color normal 176 | ) = (__sf_section_node) 177 | end 178 | 179 | test "Setting SPACEFISH_NODE_DEFAULT_VERSION to the current version disables the section" 180 | ( 181 | mkdir /tmp/tmp-spacefish/node_modules 182 | set sf_exit_code 0 183 | set SPACEFISH_NODE_DEFAULT_VERSION v9.8.0 184 | ) = (__sf_section_node) 185 | end 186 | 187 | test "doesn't display the section when SPACEFISH_NODE_SHOW is set to \"false\"" 188 | ( 189 | mkdir /tmp/tmp-spacefish/node_modules 190 | set SPACEFISH_NODE_SHOW false 191 | ) = (__sf_section_node) 192 | end 193 | -------------------------------------------------------------------------------- /tests/__sf_section_docker.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | set -l LOCAL_DOCKER_VERSION 18.06.1 3 | 4 | function setup 5 | spacefish_test_setup 6 | mock docker version 0 "echo \"18.06.1\"" 7 | mkdir -p /tmp/tmp-spacefish 8 | cd /tmp/tmp-spacefish 9 | end 10 | 11 | function teardown 12 | rm -rf /tmp/tmp-spacefish 13 | if test "$COMPOSE_FILE" 14 | set -e COMPOSE_FILE 15 | end 16 | if test "$DOCKER_MACHINE_NAME" 17 | set -e DOCKER_MACHINE_NAME 18 | end 19 | end 20 | 21 | test "Prints section when only Dockerfile is present" 22 | ( 23 | touch Dockerfile 24 | 25 | set_color --bold 26 | echo -n "is " 27 | set_color normal 28 | set_color --bold cyan 29 | echo -n "🐳 v$LOCAL_DOCKER_VERSION" 30 | set_color normal 31 | set_color --bold 32 | echo -n " " 33 | set_color normal 34 | ) = (__sf_section_docker) 35 | end 36 | 37 | test "Prints section when only docker-compose.yml is present" 38 | ( 39 | touch docker-compose.yml 40 | 41 | set_color --bold 42 | echo -n "is " 43 | set_color normal 44 | set_color --bold cyan 45 | echo -n "🐳 v$LOCAL_DOCKER_VERSION" 46 | set_color normal 47 | set_color --bold 48 | echo -n " " 49 | set_color normal 50 | ) = (__sf_section_docker) 51 | end 52 | 53 | test "Prints section when both Dockerfile and docker-compose.yml are present" 54 | ( 55 | touch Dockerfile 56 | touch docker-compose.yml 57 | 58 | set_color --bold 59 | echo -n "is " 60 | set_color normal 61 | set_color --bold cyan 62 | echo -n "🐳 v$LOCAL_DOCKER_VERSION" 63 | set_color normal 64 | set_color --bold 65 | echo -n " " 66 | set_color normal 67 | ) = (__sf_section_docker) 68 | end 69 | 70 | test "Prints Docker section when COMPOSE_FILE is set and the $COMPOSE_FILE exists" 71 | ( 72 | set -g COMPOSE_FILE /tmp/some-compose-file.yml 73 | touch /tmp/some-compose-file.yml 74 | 75 | set_color --bold 76 | echo -n "is " 77 | set_color normal 78 | set_color --bold cyan 79 | echo -n "🐳 v$LOCAL_DOCKER_VERSION" 80 | set_color normal 81 | set_color --bold 82 | echo -n " " 83 | set_color normal 84 | ) = (__sf_section_docker) 85 | end 86 | 87 | test "Prints section when only Dockerfile is present with DOCKER_MACHINE_NAME set" 88 | ( 89 | rm /tmp/some-compose-file.yml 90 | touch Dockerfile 91 | set -g DOCKER_MACHINE_NAME some-machine-name 92 | 93 | set_color --bold 94 | echo -n "is " 95 | set_color normal 96 | set_color --bold cyan 97 | echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME" 98 | set_color normal 99 | set_color --bold 100 | echo -n " " 101 | set_color normal 102 | ) = (__sf_section_docker) 103 | end 104 | 105 | test "Prints section when only docker-compose.yml is present with DOCKER_MACHINE_NAME set" 106 | ( 107 | touch docker-compose.yml 108 | set -g DOCKER_MACHINE_NAME some-machine-name 109 | 110 | set_color --bold 111 | echo -n "is " 112 | set_color normal 113 | set_color --bold cyan 114 | echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME" 115 | set_color normal 116 | set_color --bold 117 | echo -n " " 118 | set_color normal 119 | ) = (__sf_section_docker) 120 | end 121 | 122 | test "Prints section when both Dockerfile and docker-compose.yml are present with DOCKER_MACHINE_NAME set" 123 | ( 124 | touch Dockerfile 125 | touch docker-compose.yml 126 | set -g DOCKER_MACHINE_NAME some-machine-name 127 | 128 | set_color --bold 129 | echo -n "is " 130 | set_color normal 131 | set_color --bold cyan 132 | echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME" 133 | set_color normal 134 | set_color --bold 135 | echo -n " " 136 | set_color normal 137 | ) = (__sf_section_docker) 138 | end 139 | 140 | test "Prints Docker section when COMPOSE_FILE is set with DOCKER_MACHINE_NAME set" 141 | ( 142 | set -g COMPOSE_FILE /tmp/some-compose-file.yml 143 | touch /tmp/some-compose-file.yml 144 | set -g DOCKER_MACHINE_NAME some-machine-name 145 | 146 | set_color --bold 147 | echo -n "is " 148 | set_color normal 149 | set_color --bold cyan 150 | echo -n "🐳 v$LOCAL_DOCKER_VERSION via $DOCKER_MACHINE_NAME" 151 | set_color normal 152 | set_color --bold 153 | echo -n " " 154 | set_color normal 155 | ) = (__sf_section_docker) 156 | end 157 | 158 | test "Changing SPACEFISH_DOCKER_SYMBOL changes the displayed character" 159 | ( 160 | rm /tmp/some-compose-file.yml 161 | set SPACEFISH_DOCKER_SYMBOL "· " 162 | touch Dockerfile 163 | 164 | set_color --bold 165 | echo -n "is " 166 | set_color normal 167 | set_color --bold cyan 168 | echo -n "· v$LOCAL_DOCKER_VERSION" 169 | set_color normal 170 | set_color --bold 171 | echo -n " " 172 | set_color normal 173 | ) = (__sf_section_docker) 174 | end 175 | 176 | test "Changing SPACEFISH_DOCKER_PREFIX changes the character prefix" 177 | ( 178 | set sf_exit_code 0 179 | set SPACEFISH_DOCKER_PREFIX · 180 | touch Dockerfile 181 | 182 | set_color --bold 183 | echo -n "·" 184 | set_color normal 185 | set_color --bold cyan 186 | echo -n "🐳 v$LOCAL_DOCKER_VERSION" 187 | set_color normal 188 | set_color --bold 189 | echo -n " " 190 | set_color normal 191 | ) = (__sf_section_docker) 192 | end 193 | 194 | 195 | # Negative 196 | test "Doesn't display section when SPACEFISH_DOCKER_SHOW is set to 'false'" 197 | ( 198 | set SPACEFISH_DOCKER_SHOW false 199 | touch Dockerfile 200 | 201 | ) = (__sf_section_docker) 202 | end 203 | 204 | test "Doesn't print section if docker is not installed" 205 | ( 206 | touch Dockerfile 207 | mock docker version 127 208 | ) = (__sf_section_docker) 209 | end 210 | 211 | # This case can be checked only by bringing down the docker deamon 212 | test "Doesn't print section if docker deamon is not running" 213 | () = (__sf_section_docker) 214 | end 215 | 216 | test "Doesn't print section when not in a directory with Dockerfile or docker-compose.yml" 217 | () = (__sf_section_docker) 218 | end 219 | -------------------------------------------------------------------------------- /docs/API.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | This page describes the Spacefish API for creating plugins and tweaking Spacefish's behavior. 4 | 5 | Spacefish uses the `SPACEFISH_` prefix for variables and the `__sf_` prefix for functions to avoid namespace collisions. All sections, including custom ones, are required to use the `__sf_` prefix before their name to load correctly. 6 | 7 | ## Example section 8 | 9 | Below is an example of a typical section for Spacefish. Pay attention to a few critical aspects: 10 | 11 | * Variables used for configuration should start with `SPACEFISH_`. 12 | * The section's name should start with `__sf_`. 13 | * Only show the section as is needed (only in directories containing specific files, when a specific command is available, etc). 14 | 15 | Take a look at [Contribution guidelines](../CONTRIBUTING.md) for further details. 16 | 17 | ```sh 18 | # 19 | # Foobar 20 | # 21 | # Foobar is a supa-dupa cool tool for making you development easier. 22 | # Link: https://www.foobar.xyz 23 | 24 | # __sf_ prefix before section's name is required! 25 | # Otherwise this section won't be loaded. 26 | function __sf_section_foobar -d "Show foobar status" 27 | # ------------------------------------------------------------------------------ 28 | # Configuration 29 | # ------------------------------------------------------------------------------ 30 | 31 | __sf_util_set_default SPACEFISH_FOOBAR_SHOW true 32 | __sf_util_set_default SPACEFISH_FOOBAR_PREFIX $SPACEFISH_PROMPT_DEFAULT_PREFIX 33 | __sf_util_set_default SPACEFISH_FOOBAR_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX 34 | __sf_util_set_default SPACEFISH_FOOBAR_SYMBOL "🍷 " 35 | __sf_util_set_default SPACEFISH_FOOBAR_COLOR white 36 | 37 | # ------------------------------------------------------------------------------ 38 | # Section 39 | # ------------------------------------------------------------------------------ 40 | 41 | # If SPACEFISH_FOOBAR_SHOW is false, don't show the foobar section 42 | [ $SPACEFISH_FOOBAR_SHOW = false ]; and return 43 | 44 | # If the foobar command doesn't exist, don't show the foobar section 45 | type -q foobar; or return 46 | 47 | # Here some of the various expressions that can be tested 48 | # The full list can be found here: 49 | # https://fishshell.com/docs/current/commands.html#test 50 | type -q command # test that a command exists 51 | test -e /path/to/file # test that a file exists 52 | test -d /path/to/dir # test that a directory exists 53 | test operand1 = operand2 # that for two equal strings 54 | test -n "$variable" # test that a variable exists 55 | 56 | # Use `set -l` to define local variables to avoid populating 57 | # the global namespace 58 | set -l foobar_status 59 | 60 | if test "$SOME_CONDITION" = "true" 61 | set foobar_status (foobar baz) 62 | else 63 | set foobar_status (foobar foo) 64 | end 65 | 66 | # Display the foobar section 67 | __sf_lib_section \ 68 | $SPACEFISH_FOOBAR_COLOR \ 69 | $SPACEFISH_FOOBAR_PREFIX \ 70 | $SPACEFISH_FOOBAR_SYMBOL \ 71 | $SPACEFISH_FOOBAR_SUFFIX 72 | end 73 | ``` 74 | 75 | ## `SPACEFISH_VERSION` 76 | 77 | An environment variable that defines the version of currently running Spacefish prompt. Can be used for issue reporting or debugging purposes. 78 | 79 | Accessible to any program or script running in a current shell session. 80 | 81 | ### Example 82 | 83 | ```sh 84 | echo $SPACEFISH_VERSION 85 | #> 0.1.0 86 | ``` 87 | 88 | ## `__sf_lib_section [prefix] [suffix]` 89 | 90 | This function prints out the prompt section prefixed with `prefix`, suffixed with `suffix` and `content` formatted to display in `color`. The **Bold** style is applied by default. 91 | 92 | `prefix`, `suffix` and `content` can contain `set_color` to set an additional foreground color, background color or other formatting styles. Read more about `set_color` in the [set_color - set the terminal color](https://fishshell.com/docs/current/commands.html#set_color) section of the Fish Shell documentation. 93 | 94 | If `SPACEFISH_PROMPT_PREFIXES_SHOW` is `false` or if the section is the first to appear in the prompt, then `prefix` will be omitted. 95 | 96 | If `SPACEFISH_PROMPT_SUFFIXES_SHOW` is `false`, then `suffix` will be omitted. 97 | 98 | Both `prefix` and `suffix` are optional. They are equal to empty strings by default. 99 | 100 | ### Arguments 101 | 102 | 1. `color` _Required_ — The color used when displaying the `content`. Can be any of the valid [basic colors](https://fishshell.com/docs/current/commands.html#set_color) or can be any valid RGB hex code. 103 | 2. `prefix` _Optional_ — The prefix shown before `content`. Usually, it's the value of `SPACEFISH_*_PREFIX`. 104 | 3. `content` _Required_ — The content of the section. Can be any valid value or the result of command execution. 105 | 4. `suffix` _Optional_ — The suffix shown after `content`. Usually, it's the value of `SPACEFISH_*_SUFFIX`. 106 | 107 | ### Example 108 | 109 | ```sh 110 | # Display the prompt section with a prefix and suffix 111 | # Backslash is used to escape the line endings 112 | __sf_lib_section \ 113 | $SPACEFISH_SECTION_COLOR \ 114 | $SPACEFISH_SECTION_PREFIX \ 115 | $SPACEFISH_SECTION_SYMBOL$section_content \ 116 | $SPACEFISH_SECTION_SUFFIX 117 | 118 | # Display prompt section without prefix and suffix 119 | __sf_lib_section $color $SPACEFISH_CHAR_SYMBOL 120 | ``` 121 | 122 | ## `__sf_util_set_default ` 123 | 124 | This utility function is used to define a default value for a variable while allowing it to be overwritten by a user's personal configuration files (e.g. setting it in their `config.fish`) 125 | 126 | ### Arguments 127 | 128 | 1. `variable_name` _Required_ — the name of the configuration variable. 129 | 2. `value` _Required_ — the value to be assigned by default. 130 | 131 | ### Example 132 | 133 | ```sh 134 | # Preassign a value to `SPACEFISH_CHAR_SYMBOL` 135 | set -g SPACEFISH_CHAR_SYMBOL ❯ 136 | 137 | # Assign a value if one doesn't already exist 138 | __sf_util_set_default SPACEFISH_CHAR_SYMBOL ■ 139 | __sf_util_set_default SPACEFISH_RUBY_SYMBOL 💎 140 | 141 | # The original value assigned is used 142 | echo $SPACEFISH_CHAR_SYMBOL 143 | #> ❯ 144 | 145 | echo $SPACEFISH_RUBY_SYMBOL 146 | #> 💎 147 | ``` 148 | 149 | ## `__sf_util_git_branch` 150 | 151 | This utility returns the current branch name if the current working directory is a Git repository, and will return nothing if it's not. 152 | 153 | ### Example 154 | 155 | ```sh 156 | # Return if the current working directory is not a Git repository 157 | [ -z (__sf_util_git_branch) ]; and return 158 | 159 | # Print the Git branch name of the current working directory 160 | echo (__sf_util_git_branch) 161 | #> master 162 | ``` 163 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "spacefish", 3 | "projectOwner": "matchai", 4 | "repoType": "github", 5 | "repoHost": "https://github.com", 6 | "files": [ 7 | "README.md" 8 | ], 9 | "imageSize": 100, 10 | "commit": true, 11 | "contributors": [ 12 | { 13 | "login": "matchai", 14 | "name": "Matan Kushner", 15 | "avatar_url": "https://avatars0.githubusercontent.com/u/4658208?v=4", 16 | "profile": "https://twitter.com/matchai", 17 | "contributions": [ 18 | "bug", 19 | "code", 20 | "doc", 21 | "review", 22 | "test", 23 | "tool", 24 | "design" 25 | ] 26 | }, 27 | { 28 | "login": "sirMerr", 29 | "name": "Tiffany Le-Nguyen", 30 | "avatar_url": "https://avatars2.githubusercontent.com/u/11183523?v=4", 31 | "profile": "https://github.com/sirMerr", 32 | "contributions": [ 33 | "bug", 34 | "code", 35 | "doc", 36 | "review", 37 | "test" 38 | ] 39 | }, 40 | { 41 | "login": "Snuggle", 42 | "name": "Snuggle", 43 | "avatar_url": "https://avatars0.githubusercontent.com/u/26250962?v=4", 44 | "profile": "https://github.com/Snuggle", 45 | "contributions": [ 46 | "bug", 47 | "code", 48 | "doc", 49 | "review", 50 | "test" 51 | ] 52 | }, 53 | { 54 | "login": "jskrnbindra", 55 | "name": "Jaskaran Bindra", 56 | "avatar_url": "https://avatars2.githubusercontent.com/u/11844760?v=4", 57 | "profile": "https://github.com/jskrnbindra", 58 | "contributions": [ 59 | "code", 60 | "doc", 61 | "test" 62 | ] 63 | }, 64 | { 65 | "login": "kulabun", 66 | "name": "Konstantin Labun", 67 | "avatar_url": "https://avatars3.githubusercontent.com/u/6306918?v=4", 68 | "profile": "https://labun.me", 69 | "contributions": [ 70 | "code", 71 | "doc", 72 | "test" 73 | ] 74 | }, 75 | { 76 | "login": "kyleholzinger", 77 | "name": "Kyle Holzinger", 78 | "avatar_url": "https://avatars0.githubusercontent.com/u/2652762?v=4", 79 | "profile": "https://medium.com/@kyleholzinger", 80 | "contributions": [ 81 | "code", 82 | "doc" 83 | ] 84 | }, 85 | { 86 | "login": "salmanulfarzy", 87 | "name": "Salmanul Farzy", 88 | "avatar_url": "https://avatars0.githubusercontent.com/u/10276208?v=4", 89 | "profile": "https://github.com/salmanulfarzy", 90 | "contributions": [ 91 | "code", 92 | "review" 93 | ] 94 | }, 95 | { 96 | "login": "owais", 97 | "name": "owais", 98 | "avatar_url": "https://avatars0.githubusercontent.com/u/46186?v=4", 99 | "profile": "https://owais.lone.pw", 100 | "contributions": [ 101 | "code", 102 | "doc", 103 | "test" 104 | ] 105 | }, 106 | { 107 | "login": "ladysamantha", 108 | "name": "Samantha Enders", 109 | "avatar_url": "https://avatars3.githubusercontent.com/u/35412203?v=4", 110 | "profile": "https://github.com/ladysamantha", 111 | "contributions": [ 112 | "code", 113 | "doc", 114 | "test" 115 | ] 116 | }, 117 | { 118 | "login": "evanrelf", 119 | "name": "Evan Relf", 120 | "avatar_url": "https://avatars2.githubusercontent.com/u/887196?v=4", 121 | "profile": "https://evanrelf.com", 122 | "contributions": [ 123 | "code", 124 | "doc" 125 | ] 126 | }, 127 | { 128 | "login": "JasonEtco", 129 | "name": "Jason Etcovitch", 130 | "avatar_url": "https://avatars1.githubusercontent.com/u/10660468?v=4", 131 | "profile": "https://jasonet.co", 132 | "contributions": [ 133 | "code", 134 | "doc" 135 | ] 136 | }, 137 | { 138 | "login": "hrvoj3e", 139 | "name": "hrvoj3e", 140 | "avatar_url": "https://avatars0.githubusercontent.com/u/4988133?v=4", 141 | "profile": "https://github.com/hrvoj3e", 142 | "contributions": [ 143 | "bug", 144 | "code" 145 | ] 146 | }, 147 | { 148 | "login": "newmaniese", 149 | "name": "Michael Newman", 150 | "avatar_url": "https://avatars1.githubusercontent.com/u/64894?v=4", 151 | "profile": "http://newmaniese.com", 152 | "contributions": [ 153 | "bug", 154 | "code", 155 | "doc", 156 | "test" 157 | ] 158 | }, 159 | { 160 | "login": "k-lyda", 161 | "name": "Konrad", 162 | "avatar_url": "https://avatars0.githubusercontent.com/u/6491400?v=4", 163 | "profile": "https://github.com/k-lyda", 164 | "contributions": [ 165 | "bug" 166 | ] 167 | }, 168 | { 169 | "login": "dubnev", 170 | "name": "Will Neville", 171 | "avatar_url": "https://avatars1.githubusercontent.com/u/3227558?v=4", 172 | "profile": "https://github.com/dubnev", 173 | "contributions": [ 174 | "bug" 175 | ] 176 | }, 177 | { 178 | "login": "danieltrautmann", 179 | "name": "Daniel Trautmann", 180 | "avatar_url": "https://avatars1.githubusercontent.com/u/4022138?v=4", 181 | "profile": "https://github.com/danieltrautmann", 182 | "contributions": [ 183 | "code" 184 | ] 185 | }, 186 | { 187 | "login": "Menturan", 188 | "name": "Jonas Öhlander", 189 | "avatar_url": "https://avatars0.githubusercontent.com/u/16061385?v=4", 190 | "profile": "https://github.com/Menturan", 191 | "contributions": [ 192 | "bug" 193 | ] 194 | }, 195 | { 196 | "login": "lynzt", 197 | "name": "lindsay", 198 | "avatar_url": "https://avatars1.githubusercontent.com/u/3099491?v=4", 199 | "profile": "https://twitter.com/lynzt", 200 | "contributions": [ 201 | "doc" 202 | ] 203 | }, 204 | { 205 | "login": "bradcypert", 206 | "name": "Brad", 207 | "avatar_url": "https://avatars0.githubusercontent.com/u/1455979?v=4", 208 | "profile": "http://www.bradcypert.com", 209 | "contributions": [ 210 | "code" 211 | ] 212 | }, 213 | { 214 | "login": "nammn", 215 | "name": "Nam Nguyen", 216 | "avatar_url": "https://avatars3.githubusercontent.com/u/23652004?v=4", 217 | "profile": "https://github.com/nammn", 218 | "contributions": [ 219 | "code" 220 | ] 221 | }, 222 | { 223 | "login": "halostatue", 224 | "name": "Austin Ziegler", 225 | "avatar_url": "https://avatars3.githubusercontent.com/u/11361?v=4", 226 | "profile": "http://www.halostatue.ca/", 227 | "contributions": [ 228 | "review" 229 | ] 230 | }, 231 | { 232 | "login": "kouk", 233 | "name": "Konstantinos Koukopoulos", 234 | "avatar_url": "https://avatars1.githubusercontent.com/u/456007?v=4", 235 | "profile": "http://kouk.surukle.me", 236 | "contributions": [ 237 | "code", 238 | "test" 239 | ] 240 | } 241 | ], 242 | "contributorsPerLine": 7 243 | } 244 | -------------------------------------------------------------------------------- /tests/__sf_section_dir.test.fish: -------------------------------------------------------------------------------- 1 | source $DIRNAME/spacefish_test_setup.fish 2 | 3 | function setup 4 | spacefish_test_setup 5 | mkdir -p ~/.tmp-spacefish/dir1/dir2 6 | mkdir -p /tmp/tmp-spacefish/dir1/dir2/dir3 7 | mkdir -p /tmp/tmp-spacefish/writeProtected 8 | chmod 500 /tmp/tmp-spacefish/writeProtected 9 | # disabling SPACEFISH_DIR_LOCK_SYMBOL to avoid breaking old tests 10 | set SPACEFISH_DIR_LOCK_SHOW false 11 | end 12 | 13 | function teardown 14 | rm -rf ~/.tmp-spacefish 15 | rm -rf /tmp/tmp-spacefish 16 | end 17 | 18 | # 19 | # Home directory 20 | # 21 | 22 | test "Correctly truncates home directory" 23 | ( 24 | cd ~ 25 | 26 | set_color --bold 27 | echo -n "in " 28 | set_color normal 29 | set_color --bold cyan 30 | echo -n "~" 31 | set_color normal 32 | set_color --bold 33 | echo -n " " 34 | set_color normal 35 | ) = (__sf_section_dir) 36 | end 37 | 38 | test "Correctly truncates a home subdirectory" 39 | ( 40 | cd ~/.tmp-spacefish/dir1/ 41 | 42 | set_color --bold 43 | echo -n "in " 44 | set_color normal 45 | set_color --bold cyan 46 | echo -n "~/.tmp-spacefish/dir1" 47 | set_color normal 48 | set_color --bold 49 | echo -n " " 50 | set_color normal 51 | ) = (__sf_section_dir) 52 | end 53 | 54 | test "Correctly truncates a deeply nested home subdirectory" 55 | ( 56 | cd ~/.tmp-spacefish/dir1/dir2 57 | 58 | set_color --bold 59 | echo -n "in " 60 | set_color normal 61 | set_color --bold cyan 62 | echo -n ".tmp-spacefish/dir1/dir2" 63 | set_color normal 64 | set_color --bold 65 | echo -n " " 66 | set_color normal 67 | ) = (__sf_section_dir) 68 | end 69 | 70 | # 71 | # Root directory 72 | # 73 | 74 | test "Correctly truncates root directory" 75 | ( 76 | cd / 77 | 78 | set_color --bold 79 | echo -n "in " 80 | set_color normal 81 | set_color --bold cyan 82 | echo -n "/" 83 | set_color normal 84 | set_color --bold 85 | echo -n " " 86 | set_color normal 87 | ) = (__sf_section_dir) 88 | end 89 | 90 | test "Correctly truncates a root subdirectory" 91 | ( 92 | cd /usr 93 | 94 | set_color --bold 95 | echo -n "in " 96 | set_color normal 97 | set_color --bold cyan 98 | echo -n "/usr" 99 | set_color normal 100 | set_color --bold 101 | echo -n " " 102 | set_color normal 103 | ) = (__sf_section_dir) 104 | end 105 | 106 | test "Correctly truncates a deeply nested root subdirectory" 107 | ( 108 | cd /tmp/tmp-spacefish/dir1/dir2 109 | 110 | set_color --bold 111 | echo -n "in " 112 | set_color normal 113 | set_color --bold cyan 114 | echo -n "tmp-spacefish/dir1/dir2" 115 | set_color normal 116 | set_color --bold 117 | echo -n " " 118 | set_color normal 119 | ) = (__sf_section_dir) 120 | end 121 | 122 | # 123 | # Git directory 124 | # 125 | 126 | test "Correctly truncates the root of a git directory" 127 | ( 128 | cd /tmp/tmp-spacefish 129 | command git init >/dev/null 130 | 131 | set_color --bold 132 | echo -n "in " 133 | set_color normal 134 | set_color --bold cyan 135 | echo -n "tmp-spacefish" 136 | set_color normal 137 | set_color --bold 138 | echo -n " " 139 | set_color normal 140 | ) = (__sf_section_dir) 141 | end 142 | 143 | test "Correctly truncates a git subdirectory" 144 | ( 145 | cd /tmp/tmp-spacefish 146 | command git init >/dev/null 147 | cd /tmp/tmp-spacefish/dir1 148 | 149 | set_color --bold 150 | echo -n "in " 151 | set_color normal 152 | set_color --bold cyan 153 | echo -n "tmp-spacefish/dir1" 154 | set_color normal 155 | set_color --bold 156 | echo -n " " 157 | set_color normal 158 | ) = (__sf_section_dir) 159 | end 160 | 161 | test "Correctly truncates a deeply nested git subdirectory" 162 | ( 163 | cd /tmp/tmp-spacefish 164 | command git init >/dev/null 165 | cd /tmp/tmp-spacefish/dir1/dir2/dir3 166 | 167 | set_color --bold 168 | echo -n "in " 169 | set_color normal 170 | set_color --bold cyan 171 | echo -n "dir1/dir2/dir3" 172 | set_color normal 173 | set_color --bold 174 | echo -n " " 175 | set_color normal 176 | ) = (__sf_section_dir) 177 | end 178 | 179 | test "Correctly truncates the root of a git directory within another" 180 | ( 181 | cd /tmp/tmp-spacefish 182 | command git init >/dev/null 183 | 184 | cd /tmp/tmp-spacefish/dir1 185 | command git init >/dev/null 186 | 187 | set_color --bold 188 | echo -n "in " 189 | set_color normal 190 | set_color --bold cyan 191 | echo -n "dir1" 192 | set_color normal 193 | set_color --bold 194 | echo -n " " 195 | set_color normal 196 | ) = (__sf_section_dir) 197 | end 198 | 199 | test "Doesn't throw an error when in a .git directory" 200 | ( 201 | cd /tmp/tmp-spacefish 202 | command git init >/dev/null 203 | 204 | cd /tmp/tmp-spacefish/.git 205 | 206 | set_color --bold 207 | echo -n "in " 208 | set_color normal 209 | set_color --bold cyan 210 | echo -n "tmp/tmp-spacefish/.git" 211 | set_color normal 212 | set_color --bold 213 | echo -n " " 214 | set_color normal 215 | ) = (__sf_section_dir) 216 | 217 | # 218 | # Configuration 219 | # 220 | 221 | test "Doesn't show if SPACEFISH_DIR_SHOW is false" 222 | ( 223 | set SPACEFISH_DIR_SHOW false 224 | ) = (__sf_section_dir) 225 | end 226 | 227 | test "Changing SPACEFISH_DIR_PREFIX changes the dir prefix" 228 | ( 229 | set SPACEFISH_DIR_PREFIX · 230 | cd ~ 231 | 232 | set_color --bold 233 | echo -n "·" 234 | set_color normal 235 | set_color --bold cyan 236 | echo -n "~" 237 | set_color normal 238 | set_color --bold 239 | echo -n " " 240 | set_color normal 241 | ) = (__sf_section_dir) 242 | end 243 | 244 | test "Changing SPACEFISH_DIR_SUFFIX changes the dir prefix" 245 | ( 246 | set SPACEFISH_DIR_SUFFIX · 247 | cd ~ 248 | 249 | set_color --bold 250 | echo -n "in " 251 | set_color normal 252 | set_color --bold cyan 253 | echo -n "~" 254 | set_color normal 255 | set_color --bold 256 | echo -n "·" 257 | set_color normal 258 | ) = (__sf_section_dir) 259 | end 260 | 261 | # SPACEFISH_DIR_TRUNC functionality is further tested in: 262 | # __sf_util_truncate_dir.test.fish 263 | test "Changing SPACEFISH_DIR_TRUNC changes the dir length" 264 | ( 265 | set SPACEFISH_DIR_TRUNC 1 266 | cd /tmp/tmp-spacefish/dir1/dir2/dir3 267 | 268 | set_color --bold 269 | echo -n "in " 270 | set_color normal 271 | set_color --bold cyan 272 | echo -n "dir3" 273 | set_color normal 274 | set_color --bold 275 | echo -n " " 276 | set_color normal 277 | ) = (__sf_section_dir) 278 | end 279 | 280 | test "Disabling SPACEFISH_DIR_TRUNC_REPO stops repo dir truncation" 281 | ( 282 | set SPACEFISH_DIR_TRUNC_REPO false 283 | cd ~/.tmp-spacefish 284 | command git init >/dev/null 285 | 286 | set_color --bold 287 | echo -n "in " 288 | set_color normal 289 | set_color --bold cyan 290 | echo -n "~/.tmp-spacefish" 291 | set_color normal 292 | set_color --bold 293 | echo -n " " 294 | set_color normal 295 | ) = (__sf_section_dir) 296 | end 297 | 298 | test "Changing SPACEFISH_DIR_COLOR changes the dir color" 299 | ( 300 | set SPACEFISH_DIR_COLOR red 301 | cd ~ 302 | 303 | set_color --bold 304 | echo -n "in " 305 | set_color normal 306 | set_color --bold red 307 | echo -n "~" 308 | set_color normal 309 | set_color --bold 310 | echo -n " " 311 | set_color normal 312 | ) = (__sf_section_dir) 313 | end 314 | 315 | 316 | # 317 | # SPACEFISH_DIR_LOCK_SYMBOL 318 | # 319 | 320 | test "Shows DIR_LOCK_SYMBOL if in a dir with no write permissions and SPACEFISH_DIR_LOCK_SHOW is true" 321 | ( 322 | cd /tmp/tmp-spacefish/writeProtected 323 | 324 | set_color --bold 325 | echo -n "in " 326 | set_color normal 327 | set_color --bold cyan 328 | echo -n "tmp/tmp-spacefish/writeProtected" 329 | set_color normal 330 | set_color --bold 331 | echo -n " " 332 | set_color normal 333 | ) = (__sf_section_dir) 334 | end 335 | 336 | test "Doesn't show DIR_LOCK_SYMBOL if SPACEFISH_DIR_LOCK_SHOW is false" 337 | ( 338 | cd /tmp/tmp-spacefish/writeProtected 339 | 340 | set_color --bold 341 | echo -n "in " 342 | set_color normal 343 | set_color --bold cyan 344 | echo -n "tmp/tmp-spacefish/writeProtected" 345 | set_color normal 346 | set_color --bold 347 | echo -n " " 348 | set_color normal 349 | ) = (__sf_section_dir) 350 | end 351 | 352 | test "Doesn't show DIR_LOCK_SYMBOL if current directory is not write protected for this user" 353 | ( 354 | cd ~ 355 | 356 | set_color --bold 357 | echo -n "in " 358 | set_color normal 359 | set_color --bold cyan 360 | echo -n "~" 361 | set_color normal 362 | set_color --bold 363 | echo -n " " 364 | set_color normal 365 | ) = (__sf_section_dir) 366 | end 367 | 368 | test "Changing SPACEFISH_DIR_LOCK_SYMBOL changes the symbol" 369 | ( 370 | set SPACEFISH_DIR_LOCK_SYMBOL "😀" 371 | cd /tmp/tmp-spacefish/writeProtected 372 | 373 | set_color --bold 374 | echo -n "in " 375 | set_color normal 376 | set_color --bold cyan 377 | echo -n "tmp/tmp-spacefish/writeProtected" 378 | set_color normal 379 | set_color --bold 380 | echo -n " " 381 | set_color normal 382 | ) = (__sf_section_dir) 383 | end 384 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Focus has shifted to the development of Starship, the successor to Spacefish. If you are interested in contributing or using it, come take a look! 4 |

5 | 6 | spacefish fish shell theme 7 | 8 |
9 |
Spacefish 🚀🐟
10 |

11 | 12 |

13 | Fish Shell prompt for Astronauts. 14 |

15 | 16 |

17 | 18 | Mac OSX & Linux CI Status 20 | 21 | 22 | Fish Version 24 | 25 | 26 | GitHub License 27 | 28 |

29 | 30 |
31 |

32 | Website | 33 | Install | 34 | Features | 35 | Options | 36 | API 37 |

38 |
39 | 40 |
41 | Built with ❤︎ by 42 | Matan Kushner and 43 | contributors 44 |
45 | A port of Spaceship ZSH by 46 | Denys Dovhan 47 |
48 | 49 |
50 | Spacefish is a minimalistic, powerful and extremely customizable Fish Shell prompt. It combines everything you may need for convenient work, without unnecessary complications, like a real spacefish. 51 | 52 |

53 | Spaceship with Hyper and One Dark 54 |

55 | 56 | Vist Troubleshooting for instructions to recreate this terminal setup. 57 | 58 | ## Features 59 | 60 | * Clever hostname and username displaying. 61 | * Indicator if user is root. 62 | * Prompt character turns red if the last command exits with non-zero code. 63 | * Current Git branch and rich repo status: 64 | * `?` — untracked changes; 65 | * `+` — uncommitted changes in the index; 66 | * `!` — unstaged changes; 67 | * `»` — renamed files; 68 | * `✘` — deleted files; 69 | * `$` — stashed changes; 70 | * `=` — unmerged changes; 71 | * `⇡` — ahead of remote branch; 72 | * `⇣` — behind of remote branch; 73 | * `⇕` — diverged changes. 74 | * Indicator for jobs in the background (`✦`). 75 | * Current Node.js version, through nvm/nodenv/n (`⬢`). 76 | * Current Docker version and connected machine (`🐳`). 77 | * Current Ruby version, through rvm/rbenv/chruby/asdf (`💎`). 78 | * Current Go version (`🐹`). 79 | * Current PHP version (`🐘`). 80 | * Current Rust version (`𝗥`). 81 | * Current version of Haskell GHC Compiler, defined in stack.yaml file (`λ`). 82 | * Current Julia version (`ஃ`). 83 | * Current Amazon Web Services (AWS) profile (`☁️`) ([Using named profiles](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html)). 84 | * Current Python virtualenv. 85 | * Current Conda version (`🅒`). 86 | * Current Elixir Version (`💧`). 87 | * Current Python pyenv (`🐍`). 88 | * Current .NET SDK version, through dotnet-cli (`.NET`). 89 | * Current Kubectl context (`☸️`). 90 | * Package version, if there is a package in current directory (`📦`). 91 | * Current battery level and status: 92 | * `⇡` - charging; 93 | * `⇣` - discharging; 94 | * `•` - fully charged. 95 | * Current Vi-mode mode. 96 | * Optional exit-code of last command. 97 | * Optional time stamps 12/24hr in format. 98 | * Execution time of the last command if it exceeds 5 seconds. 99 | 100 | Want more features? Please [open an issue](https://github.com/matchai/spacefish/issues/new?template=Feature_request.md) or send pull request! 101 | 102 | ## Requirements 103 | 104 | To get spacefish working correctly, you will need: 105 | 106 | * [`fish`][fish] (v2.7.0 or newer) 107 | * [Powerline Font](https://github.com/powerline/fonts) must be installed and enabled in your terminal. 108 | 109 | ## Installation 110 | 111 | ### [Fisher](https://github.com/jorgebucaran/fisher) 112 | 113 | ```fish 114 | $ fisher install matchai/spacefish 115 | ``` 116 | 117 | ### [Oh My Fish!](https://github.com/oh-my-fish/oh-my-fish) 118 | 119 | ```fish 120 | $ omf install spacefish 121 | ``` 122 | 123 | ## Customization 124 | 125 | Spacefish works really well out of the box, but you can customize your fish to your heart's content! 126 | 127 | * [**Options**](./docs/Options.md) — Tweak section's behavior with tons of options. 128 | 129 | You have the ability to customize or disable specific elements of Spacefish. All options must be overridden in your `config.fish`. 130 | 131 | ## Troubleshooting 132 | 133 | Having issues? Take a look at our [Troubleshooting](./docs/Troubleshooting.md) page. 134 | 135 | Still struggling? Please [file an issue](https://github.com/matchai/spacefish/issues/new?template=Support_question.md), describe your problem, and we will gladly help you. 136 | 137 | ## Contributors 138 | 139 | Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 |
Matan Kushner
Matan Kushner

🐛 💻 📖 👀 ⚠️ 🔧 🎨
Tiffany Le-Nguyen
Tiffany Le-Nguyen

🐛 💻 📖 👀 ⚠️
Snuggle
Snuggle

🐛 💻 📖 👀 ⚠️
Jaskaran Bindra
Jaskaran Bindra

💻 📖 ⚠️
Konstantin Labun
Konstantin Labun

💻 📖 ⚠️
Kyle Holzinger
Kyle Holzinger

💻 📖
Salmanul Farzy
Salmanul Farzy

💻 👀
owais
owais

💻 📖 ⚠️
Samantha Enders
Samantha Enders

💻 📖 ⚠️
Evan Relf
Evan Relf

💻 📖
Jason Etcovitch
Jason Etcovitch

💻 📖
hrvoj3e
hrvoj3e

🐛 💻
Michael Newman
Michael Newman

🐛 💻 📖 ⚠️
Konrad
Konrad

🐛
Will Neville
Will Neville

🐛
Daniel Trautmann
Daniel Trautmann

💻
Jonas Öhlander
Jonas Öhlander

🐛
lindsay
lindsay

📖
Brad
Brad

💻
Nam Nguyen
Nam Nguyen

💻
Austin Ziegler
Austin Ziegler

👀
Konstantinos Koukopoulos
Konstantinos Koukopoulos

💻 ⚠️
175 | 176 | 177 | 178 | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! 179 | 180 | ## License 181 | 182 | MIT © [Matan Kushner](http://matchai.dev) 183 | 184 | 185 | 186 | [spaceship]: https://github.com/denysdovhan/spaceship-prompt 187 | [fish]: https://fishshell.com 188 | [zsh]: http://zsh.org 189 | --------------------------------------------------------------------------------