Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 135b5c9

Browse files
author
mikkomaa
committed
Merge pull request #103 from tmc-cli/launch-script-aleksi
Launch script for tmc-cli and autocompletion
2 parents adc3033 + ec4e82f commit 135b5c9

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tmc-cli.ipr
1818
tmc-cli.iws
1919
*.sw*
2020
*~
21+
tmc
2122

2223
nbactions.xml
2324
/nbproject/

pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,33 @@
150150
</resources>
151151
</build>
152152

153+
<profiles>
154+
<profile>
155+
<activation>
156+
<os>
157+
<family>!windows</family>
158+
</os>
159+
</activation>
160+
<build>
161+
<plugins>
162+
<plugin>
163+
<artifactId>exec-maven-plugin</artifactId>
164+
<groupId>org.codehaus.mojo</groupId>
165+
<executions>
166+
<execution><!-- Create a wrapper for java binary -->
167+
<id>Script wrapper</id>
168+
<phase>package</phase>
169+
<goals>
170+
<goal>exec</goal>
171+
</goals>
172+
<configuration>
173+
<executable>${basedir}/scripts/wrapper.sh</executable>
174+
</configuration>
175+
</execution>
176+
</executions>
177+
</plugin>
178+
</plugins>
179+
</build>
180+
</profile>
181+
</profiles>
153182
</project>

scripts/autocompletion.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# SCRIPT_PATH will be filled by stub script
4+
alias tmc="$SCRIPT_PATH/tmc"
5+
6+
_tmc_opts()
7+
{
8+
local cur
9+
# Pointer to current completion word.
10+
# By convention, it's named "cur" but this isn't strictly necessary.
11+
12+
COMPREPLY=()
13+
cur=\${COMP_WORDS[COMP_CWORD]}
14+
15+
case "\$cur" in
16+
-*)
17+
COMPREPLY=( \$( compgen -W "-v -h --version --help" -- \$cur ) )
18+
return 0
19+
;;
20+
# xx) May add more cases here.
21+
# yy)
22+
# zz)
23+
esac
24+
25+
COMPREPLY=( \$( compgen -W "help download list-courses easter-egg list-exercises login" -- \$cur ) )
26+
return 0
27+
}
28+
29+
complete -F _tmc_opts tmc

scripts/stub.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
MYSELF=`which "$0" 2>/dev/null`
3+
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
4+
5+
java=java
6+
if test -n "$JAVA_HOME"; then
7+
java="$JAVA_HOME/bin/java"
8+
fi
9+
10+
if ! hash "$java" 2>/dev/null; then
11+
echo "Java not installed. If you have installed it in another directory then set the \$JAVA_HOME variable."
12+
exit 1
13+
fi
14+
15+
version=$("$java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
16+
if [ "$version" \< "1.7" ]; then
17+
echo "You must have 1.7 installed."
18+
exit 1
19+
fi
20+
21+
AUTOCOMPLETE="$HOME/.tmc-autocomplete.sh"
22+
23+
# this is used in autocompletion file
24+
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
25+
26+
if [ ! -f $AUTOCOMPLETE ]; then
27+
cat > $AUTOCOMPLETE <<- EOM
28+
TMC_AUTOCOMPLETE_SH
29+
EOM
30+
31+
echo ". $AUTOCOMPLETE" >> ~/.bashrc
32+
33+
chmod +x $AUTOCOMPLETE
34+
. $AUTOCOMPLETE
35+
fi
36+
37+
exec "$java" $java_args -jar $MYSELF "$@"
38+
exit 0

scripts/tmc

Whitespace-only changes.

scripts/wrapper.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# find newest jar file
4+
jar_file=`ls -t target/tmc-cli-*.jar | head -1`
5+
6+
sed '/TMC_AUTOCOMPLETE_SH/ {
7+
r scripts/autocompletion.sh
8+
d }' scripts/stub.sh > tmc
9+
10+
cat $jar_file >> tmc && chmod +x tmc
11+
12+
chmod +x tmc

0 commit comments

Comments
 (0)