Run Python Script in Terminal Anywhere

As I did in The Simple Way to Generate Subtitles, I created a simple script to extract the audio from a video file and generate/translate subtitles. But call ./generate-srt.sh /file/path under whisper.cpp folder is too annoying. So I am looking for a way to run the script anywhere.

Method 1: Add the script to /usr/local/bin

It's the easiest way to run the script anywhere. Just copy the script to /usr/local/bin and make it executable.

cp generate-srt.sh /usr/local/bin
chmod +x /usr/local/bin/generate-srt.sh

Method 2: Add the script to $PATH

Use zsh as an example.

vim ~/.zshrc

Add the script path to $PATH.

export PATH="/your/scripts/folder:$PATH"

And don't forget to make the script executable and reload zsh.

chmod +x /your/scripts/folder/generate-srt.sh
exec zsh

Add alias in zsh

If you want to run the script with a short command, you can add alias in zsh.

vim ~/.zshrc

Add the alias.

alias srt='/your/scripts/folder/generate-srt.sh $1 $2' // $1 is the file path, $2 is the language code

And reload zsh.

exec zsh

← Back to all posts