Skip to content

Commit

Permalink
Add init option
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddewit committed Aug 2, 2019
1 parent b420b18 commit 17e8e28
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# sly
Sly - a CLI tool
# Sly
A CLI tool utilizing plain Bash functions.

## Slyfile

Create a `Slyfile` somewhere you need it:

```bash
sly --init
```

Add functions to the `Slyfile`. They may contain any Bash code.

### Example

```bash
ping_home() {
ping -c ${1-5} 127.0.0.1
screenfetch
}
```

Then run it with `sly ping_home 10` to do 10 pings to localhost and run `screenfetch` afterwards. Or run without arguments (`sly ping_home`) to do the default 5 pings instead of 10.
31 changes: 31 additions & 0 deletions sly
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sly() {
source "$slyfile"
else
sly_error "$slyfile not found"
sly_error "Create one with ${bold}sly --init${reset}"
exit 1
fi

Expand All @@ -53,7 +54,37 @@ sly() {
$@
}

sly_init() {
if sly_has_slyfile; then
sly_error "$slyfile already exists"
exit 1
fi

cat << SLY > $slyfile
# -*- mode: sh; -*- vim: set ft=sh:
#
### $slyfile - used by sly
### https://github.com/richarddewit/sly
#
# Add your functions below. They may contain any Bash code.
# Example:
#
# ping_home() {
# ping -c \${1-5} 127.0.0.1
# screenfetch
# }
#
# Then run it with \`sly ping_home 10\` to do 10 pings to localhost and
# run \`screenfetch\` afterwards.
SLY
echo "Sly initialised into $(pwd)/$slyfile" | sly_prepend
echo "Go add some functions to the $slyfile!" | sly_prepend
exit 0
}

[ -z "$1" ] && sly_error "Missing argument COMMAND" && exit 1
[ "$1" == "--init" ] && sly_init

(sly $@)

0 comments on commit 17e8e28

Please sign in to comment.