├── .github ├── ISSUE_TEMPLATE │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── FUNDING.yml └── workflows │ └── ci.yaml ├── .editorconfig ├── .releaserc.json ├── LICENSE.md ├── CHANGELOG.md ├── spaceship-section.plugin.zsh ├── tests └── spaceship-section.test.zsh └── README.md /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: 👾 Join Discord 3 | url: https://discord.gg/Q3SaC2Bt3n 4 | about: Join our discord server to be in touch with the community. Get help, discuss new features, have fun. 5 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | #### Description 2 | 3 | 4 | 5 | #### Screenshot 6 | 7 | 10 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # You can add one username per supported platform and one custom link 2 | github: denysdovhan 3 | patreon: denysdovhan 4 | open_collective: spaceship-prompt 5 | ko_fi: # Replace with your Ko-fi username 6 | custom: [buymeacoffee.com/denysdovhan] 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig 2 | # http://EditorConfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | indent_style = space 10 | indent_size = 2 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [.gitmodules] 15 | indent_style = tab 16 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": ["main", "+([0-9])?(.{+([0-9]),x}).x"], 3 | "plugins": [ 4 | "@semantic-release/commit-analyzer", 5 | "@semantic-release/release-notes-generator", 6 | "@semantic-release/github", 7 | "@semantic-release/changelog", 8 | ["semantic-release-license", { 9 | "license": { 10 | "path": "LICENSE.md" 11 | } 12 | }], 13 | ["@semantic-release/git", { 14 | "assets": ["CHANGELOG.md", "LICENSE.md"] 15 | }] 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - +([0-9])?(.{+([0-9]),x}).x 7 | pull_request: 8 | 9 | jobs: 10 | main: 11 | name: Tests 12 | runs-on: ubuntu-latest 13 | container: ghcr.io/spaceship-prompt/spaceship-prompt:latest 14 | steps: 15 | - name: ⬇️ Checkout Repo 16 | uses: actions/checkout@v2 17 | 18 | - name: 🖨 Print Zsh Version 19 | run: zsh --version 20 | 21 | - name: 🧪 Run Tests 22 | run: ./tests/spaceship-section.test.zsh 23 | 24 | release: 25 | name: Release 26 | needs: main 27 | if: ${{ github.repository == 'spaceship-prompt/spaceship-section' && github.event_name == 'push' }} 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: ⬇️ Checkout Repo 31 | uses: actions/checkout@v2 32 | 33 | - name: 🚀 Release 34 | uses: cycjimmy/semantic-release-action@v2 35 | with: 36 | extra_plugins: | 37 | @semantic-release/changelog 38 | @semantic-release/git 39 | semantic-release-license 40 | env: 41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 42 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2016 [Name Surename](https://yourwebsite.com) 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 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.0.3](https://github.com/spaceship-prompt/spaceship-section/compare/v1.0.2...v1.0.3) (2022-09-21) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * **pr template:** remove broken link ([e229fd6](https://github.com/spaceship-prompt/spaceship-section/commit/e229fd658774109a72efbd6472ca08302bcb5c0c)) 7 | 8 | ## [1.0.2](https://github.com/spaceship-prompt/spaceship-section/compare/v1.0.1...v1.0.2) (2022-08-02) 9 | 10 | 11 | ### Bug Fixes 12 | 13 | * Update template to v4 ([3835c7d](https://github.com/spaceship-prompt/spaceship-section/commit/3835c7d7c8dce7e3d28937c16f86f4c9c96042ec)) 14 | 15 | ## [1.0.1](https://github.com/spaceship-prompt/spaceship-section/compare/v1.0.0...v1.0.1) (2022-06-01) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * specify section version ([d6a69ad](https://github.com/spaceship-prompt/spaceship-section/commit/d6a69ad7123fe4580a23e0a822cd1e0a2439ff20)) 21 | 22 | # 1.0.0 (2022-05-09) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * run proper test file ([a6df744](https://github.com/spaceship-prompt/spaceship-section/commit/a6df7446dcc57b8bcca87a03e68bbd9ef01bb62e)) 28 | * use correct token for ci ([6a27258](https://github.com/spaceship-prompt/spaceship-section/commit/6a27258d0c0ee22871c79535a350d12246b568af)) 29 | -------------------------------------------------------------------------------- /spaceship-section.plugin.zsh: -------------------------------------------------------------------------------- 1 | # 2 | # Foobar 3 | # 4 | # Foobar is a supa-dupa cool tool for making you development easier. 5 | # Link: https://www.foobar.xyz 6 | 7 | # ------------------------------------------------------------------------------ 8 | # Configuration 9 | # ------------------------------------------------------------------------------ 10 | 11 | SPACESHIP_FOOBAR_SHOW="${SPACESHIP_FOOBAR_SHOW=true}" 12 | SPACESHIP_FOOBAR_ASYNC="${SPACESHIP_FOOBAR_ASYNC=true}" 13 | SPACESHIP_FOOBAR_PREFIX="${SPACESHIP_FOOBAR_PREFIX="$SPACESHIP_PROMPT_DEFAULT_PREFIX"}" 14 | SPACESHIP_FOOBAR_SUFFIX="${SPACESHIP_FOOBAR_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" 15 | SPACESHIP_FOOBAR_SYMBOL="${SPACESHIP_FOOBAR_SYMBOL="😍 "}" 16 | SPACESHIP_FOOBAR_COLOR="${SPACESHIP_FOOBAR_COLOR="yellow"}" 17 | 18 | # ------------------------------------------------------------------------------ 19 | # Section 20 | # ------------------------------------------------------------------------------ 21 | 22 | # Show foobar status 23 | # spaceship_ prefix before section's name is required! 24 | # Otherwise this section won't be loaded. 25 | spaceship_foobar() { 26 | # If SPACESHIP_FOOBAR_SHOW is false, don't show foobar section 27 | [[ $SPACESHIP_FOOBAR_SHOW == false ]] && return 28 | 29 | # Check if foobar command is available for execution 30 | spaceship::exists foobar || return 31 | 32 | # Show foobar section only when there are foobar-specific files in current 33 | # working directory. 34 | 35 | # spaceship::upsearch utility helps finding files up in the directory tree. 36 | local is_foobar_context="$(spaceship::upsearch foobar.conf)" 37 | # Here glob qualifiers are used to check if files with specific extension are 38 | # present in directory. Read more about them here: 39 | # http://zsh.sourceforge.net/Doc/Release/Expansion.html 40 | [[ -n "$is_foobar_context" || -n *.foo(#qN^/) || -n *.bar(#qN^/) ]] || return 41 | 42 | local foobar_version="$(foobar --version)" 43 | 44 | # Check if tool version is correct 45 | [[ $foobar_version == "system" ]] && return 46 | 47 | # Display foobar section 48 | # spaceship::section utility composes sections. Flags are optional 49 | spaceship::section::v4 \ 50 | --color "$SPACESHIP_FOOBAR_COLOR" \ 51 | --prefix "$SPACESHIP_FOOBAR_PREFIX" \ 52 | --suffix "$SPACESHIP_FOOBAR_SUFFIX" \ 53 | --symbol "$SPACESHIP_FOOBAR_SYMBOL" \ 54 | "$foobar_version" 55 | } 56 | -------------------------------------------------------------------------------- /tests/spaceship-section.test.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | # Required for shunit2 to run correctly 4 | CWD="${${(%):-%x}:A:h}" 5 | setopt shwordsplit 6 | SHUNIT_PARENT=$0 7 | 8 | # Use system Spaceship or fallback to Spaceship Docker on CI 9 | typeset -g SPACESHIP_ROOT="${SPACESHIP_ROOT:=/spaceship}" 10 | 11 | # Mocked tool CLI 12 | mocked_version="v1.0.0-mocked" 13 | foobar() { 14 | echo "$mocked_version" 15 | } 16 | 17 | # ------------------------------------------------------------------------------ 18 | # SHUNIT2 HOOKS 19 | # ------------------------------------------------------------------------------ 20 | 21 | setUp() { 22 | # Enter the test directory 23 | cd $SHUNIT_TMPDIR 24 | } 25 | 26 | oneTimeSetUp() { 27 | export TERM="xterm-256color" 28 | 29 | source "$SPACESHIP_ROOT/spaceship.zsh" 30 | source "$(dirname $CWD)/spaceship-section.plugin.zsh" 31 | 32 | SPACESHIP_PROMPT_ASYNC=false 33 | SPACESHIP_PROMPT_FIRST_PREFIX_SHOW=true 34 | SPACESHIP_PROMPT_ADD_NEWLINE=false 35 | SPACESHIP_PROMPT_ORDER=(foobar) 36 | 37 | echo "Spaceship version: $(spaceship --version)" 38 | } 39 | 40 | oneTimeTearDown() { 41 | unset SPACESHIP_PROMPT_ASYNC 42 | unset SPACESHIP_PROMPT_FIRST_PREFIX_SHOW 43 | unset SPACESHIP_PROMPT_ADD_NEWLINE 44 | unset SPACESHIP_PROMPT_ORDER 45 | } 46 | 47 | # ------------------------------------------------------------------------------ 48 | # TEST CASES 49 | # ------------------------------------------------------------------------------ 50 | 51 | test_incorrect_env() { 52 | local expected="" 53 | local actual="$(spaceship::testkit::render_prompt)" 54 | 55 | assertEquals "do not render system version" "$expected" "$actual" 56 | } 57 | 58 | test_mocked_version() { 59 | # Prepare the environment 60 | touch $SHUNIT_TMPDIR/test.foo 61 | 62 | local prefix="%{%B%}$SPACESHIP_FOOBAR_PREFIX%{%b%}" 63 | local content="%{%B%F{$SPACESHIP_FOOBAR_COLOR}%}$SPACESHIP_FOOBAR_SYMBOL$mocked_version%{%b%f%}" 64 | local suffix="%{%B%}$SPACESHIP_FOOBAR_SUFFIX%{%b%}" 65 | 66 | local expected="$prefix$content$suffix" 67 | local actual="$(spaceship::testkit::render_prompt)" 68 | 69 | assertEquals "render mocked version" "$expected" "$actual" 70 | } 71 | 72 | # ------------------------------------------------------------------------------ 73 | # SHUNIT2 74 | # Run tests with shunit2 75 | # ------------------------------------------------------------------------------ 76 | 77 | source "$SPACESHIP_ROOT/tests/shunit2/shunit2" 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
11 |
12 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
31 |
32 |