This project started from the "need" of having a compatible way to point to files indifferently if on Windows or Linux. While both operative systems can handle symbolic links, when the target file is an executable, certain scripts and programs present problems when executed through a symbolic link, as the working directory is expected to be the directory containing the executable and not the directory with the symbolic link.
For that reason, a different approach was taken. To create an hybrid script with Bash and Batch code to point to the desired files or program. This kind of script is possible by using the commenting format of Batch files to ignore the Bash commands. In this sense such files can are universal shortcuts. As the paths utilized in this universal shortcut file, are relative, it works perfectly with portable media, if and only if, the filesystem supports file permissions. Note: FAT32 does not support them.
The universal shortcuts consist of an executable script file with Bash and Batch code. When executed in Windows the Bash part is ignored and when executed in Linux the Batch part is ignored. Thus, the same script can be executed in both systems and performs the same action.
The scripts in bash and batch are equivalent and they do:
Change the current directory to the directory where the target file is
Open the target file in a similar way as when the user double clicks it, this operation depends on the Desktop Environment utilized
The universal shortcut is created by a Python 3 script that can be found in this repository:
$ python3 mk_unishortcut.py <targetpath>
<targetpath> can be absolute or relative, and can be a file or directory
When the Python script is executed in Linux it will automatically change the file permissions of the shortcut file to be executable. If the Python script is run in Windows, it is needed to change the file permissions to executable in Linux.
Despite the fact these universal shortcuts may not be extremely useful, this project was an interesting experience in writing hybrid Bash-Batch scripts.
Symbolic links fail to run executable files when they need to run in their folder
Hybrid Windows-bash and Linux-bash scripting
Identify Linux Desktop Environment
startcommand in Windows
Link with different Desktop Environments