Skip to content

Commit

Permalink
README: Refactored the shell wrapper (#205)
Browse files Browse the repository at this point in the history
Saw an opportunity to restore my sanity by refactoring bash script and i took it
  • Loading branch information
Kreyren authored Oct 18, 2021
1 parent 7ea8d29 commit d761849
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,31 @@ end

## Bash, with [fzf](https://github.com/junegunn/fzf)

Contributed by a user:
Contributed by a user (@kreyren:github.com):

```bash
#!/bin/sh
# shellcheck shell=sh # Written to comply with IEEE Std 1003.1-2017 for standard POSIX environment

###! # WorkSPace (wsp)
###! Switches to specified git-workspace project directory
###! - Requires git and fzf
wsp() {
if [[ "$#" == "0" ]]; then
fzf_arg=""
else
fzf_arg="-q"
fi
cd ${GIT_WORKSPACE}/$(git workspace list | fzf $fzf_arg "$@")
# Check for required non-standard commands
for command in ${FZF:-"fzf"} ${GIT:-"git"}; do
${COMMAND:-"command"} -v "$command" || { ${PRINTF:-"printf"} "FATAL: %s\\n" "Command '$command' is not executable"; ${EXIT:-"exit"} 127 ;}
done

# shellcheck disable=SC2086 # Harmless warning about missing double-quotes that are not expected to allow parsing multiple arguments
wsp_path="${1:-"${GTT_WORKSPACE:-"$PWD"}/$(${GIT:-"git"} workspace list | ${FZF:-"fzf"} ${fzf_arg:-"-q"} "$@")"}" # Path to the git workspace directory

# Change directory
${CD:-"cd"} "$wsp_path" || { printf "FATAL: %s\\n" "Unable to change directory to '$wsp_path'";}
}
```

Consider using [shfmt](https://github.com/patrickvane/shfmt) to optimize the file size.

# Contributing :bug:

This is my first 'proper' Rust project. If you're experienced with Rust you might puke at the code, but any feedback to help me improve would be greatly appreciated!
Expand Down

0 comments on commit d761849

Please sign in to comment.