2023-10-02 21:00:49 +02:00
|
|
|
|
# ltsh
|
2023-10-03 03:37:55 +02:00
|
|
|
|
|
|
|
|
|
**(highly experimental)**
|
|
|
|
|
|
|
|
|
|
tiny utility program for type-analysis of shell pipelines based on ladder-typing
|
|
|
|
|
|
2023-10-02 21:00:49 +02:00
|
|
|
|
<hr/>
|
|
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
|
|
```sh
|
2023-10-03 03:37:55 +02:00
|
|
|
|
[~]$ ltsh <<< 'echo -n $PATH | xargs stat -c %Y | sort -n'
|
2023-10-02 21:00:49 +02:00
|
|
|
|
```
|
|
|
|
|
```
|
|
|
|
|
--- BEGIN TYPE-ANALYSIS ---
|
|
|
|
|
|
2023-10-03 03:37:55 +02:00
|
|
|
|
* unknown stdin-type of `echo -n $PATH`
|
|
|
|
|
|
|
|
|
|
* typecheck error
|
|
|
|
|
echo -n $PATH | xargs stat -c %Y
|
|
|
|
|
<Seq Path> | <Seq Path>
|
|
|
|
|
<Seq <Seq PathSegment>> | <Seq <Seq PathSegment>>
|
|
|
|
|
<Seq <Seq <Seq Char>>> | <Seq <Seq <Seq Char>>>
|
|
|
|
|
<Seq <SepSeq Char '/'>> | <Seq <SepSeq Char '/'>>
|
|
|
|
|
<Seq <Seq Char>> | <Seq <Seq Char>>
|
|
|
|
|
<SepSeq Char ':'> | <SepSeq Char '\n'>
|
|
|
|
|
<Seq Char> | <Seq Char>
|
|
|
|
|
|
|
|
|
|
* typecheck ok
|
|
|
|
|
xargs stat -c %Y | sort -n
|
|
|
|
|
<Seq Date> |
|
|
|
|
|
<Seq <TimeSince UnixEpoch>> |
|
|
|
|
|
<Seq <Duration Seconds>> |
|
|
|
|
|
<Seq ℕ> | <Seq ℕ>
|
|
|
|
|
<Seq <PosInt 10 BigEndian>> | <Seq <PosInt 10 BigEndian>>
|
|
|
|
|
<Seq <Seq <Digit 10>>> | <Seq <Seq <Digit 10>>>
|
|
|
|
|
<Seq <Seq Char>> | <Seq <Seq Char>>
|
|
|
|
|
<SepSeq Char '\n'> | <SepSeq Char '\n'>
|
|
|
|
|
<Seq Char> | <Seq Char>
|
2023-10-02 21:00:49 +02:00
|
|
|
|
|
|
|
|
|
--- END TYPE-ANALYSIS ---
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
2023-10-03 03:37:55 +02:00
|
|
|
|
### Install
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
git clone https://github.com/michaelsippel/ltsh
|
|
|
|
|
cd ltsh
|
|
|
|
|
cargo install --path .
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Use as Zsh-Extension
|
2023-10-02 21:00:49 +02:00
|
|
|
|
To automatically check every pipeline entered during interactive shell
|
|
|
|
|
use, add the following hook to your `.zshrc`:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
preexec() {
|
2023-10-03 03:37:55 +02:00
|
|
|
|
if ! ltsh <<< "${1}";
|
|
|
|
|
then
|
|
|
|
|
echo "\e[33;1m"
|
|
|
|
|
echo "!! ltsh discoverd a type incompatibility. !!"
|
|
|
|
|
echo "!! abort [CTRL-C] or continue regardless [RET] !!"
|
|
|
|
|
echo "\e[0m"
|
|
|
|
|
read -s keys
|
|
|
|
|
fi
|
2023-10-02 21:00:49 +02:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Limitations
|
|
|
|
|
|
|
|
|
|
* only parses pipelines
|
|
|
|
|
* ignores quoting rules & expansions
|
|
|
|
|
* regex-based typedb implementation (slow & incapable)
|
|
|
|
|
|
|
|
|
|
|
2023-10-03 03:37:55 +02:00
|
|
|
|
## License
|
2023-10-02 21:00:49 +02:00
|
|
|
|
[GPLv3](COPYING)
|