This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
slink
56 lines (49 loc) · 1.34 KB
/
slink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
source "$(dirname $0)/slinky.cfg"
# command-line parsing
for param in "$@"
do
case "$param" in
"-p") no_color=1;;
* ) if [ -z "$win_command" ]
then
win_command=$param
else
linux_command=$param
fi;;
esac
done
if [ -z "$win_command" ]
then
echo "Usage: slink [-p] [win command] [linux command]"
echo ""
echo "Link [win command] in the Windows command prompt to [linux command] in Bash for Windows."
echo "By only providing one argument, the same command name will be used in Windows and Linux."
echo ""
echo " -p Disable colorized output."
exit 1
fi
if [ -z "$linux_command" ]
then
linux_command="$win_command"
fi
file_name="$install_dir/$command_prepend$win_command.bat"
dirchange_name="%~dp0.dirchange"
mkdir -p $install_dir
echo -e "@echo off\r" > $file_name
echo -e "rem $linux_command\r" >> $file_name
echo -e "\"$win_bash\" $run_file $linux_command %*\r" >> $file_name
echo -e "set dirchange=\r" >> $file_name
echo -e "set /p dirchange=<$dirchange_name\r" >> $file_name
echo -e "if defined dirchange cd %dirchange%\r" >> $file_name
chmod u=rwx,g=rx,o=r $file_name
if [ $? -ne 0 ]
then
exit 1
fi
if [ $no_color ] || [ "$use_color" != true ]
then
echo -e "$file_name ---> $linux_command"
else
echo -e "\e[36m$file_name \e[0m---> \e[36m$linux_command\e[0m"
fi