Compare commits

...

10 Commits

@ -0,0 +1,37 @@
## get-ssh-agent
# A pretty simple function intended to convince multiple shell sessions to connect to the same
# ssh-agent instance.
AGENT_FILE_NAME='ssh-agent.env'
# XDG runtime path by default is /run/user/$UID
default_runtime_path="/run/user/$UID"
if [[ "$XDG_RUNTIME_DIR" ]]; then
ssh_agent_env_file="${XDG_RUNTIME_DIR}/${AGENT_FILE_NAME}"
else
ssh_agent_env_file="${default_runtime_path}/${AGENT_FILE_NAME}"
fi
function _start_new_ssh_agent () {
ssh_agent_file=$1
killall ssh-agent
# start a new ssh-agent and write its output to the env file.
ssh-agent | grep -v echo >& "$ssh_agent_file"
source "$ssh_agent_file"
echo "New ssh-agent started."
ssh-add
}
if [[ -e "$ssh_agent_env_file" ]]; then
# determine if the pid in the env file is still alive
if [[ -n "$(source "$ssh_agent_env_file"; ps -p "$SSH_AGENT_PID")" ]]; then
source "$ssh_agent_env_file"
echo "Existing ssh-agent environment configured with pid ${SSH_AGENT_PID}."
else
echo "Existing ssh-agent appears to be dead."
_start_new_ssh_agent "$ssh_agent_env_file"
fi
else
echo "No existing ssh-agent found."
_start_new_ssh_agent "$ssh_agent_env_file"
fi

@ -0,0 +1,6 @@
## journal
# A simple function to automatically select the correct journal file.
journal_file="$(xdg-user-dir DOCUMENTS)/journal/$(date +%F).md"
"$EDITOR" "$journal_file"

@ -6,6 +6,11 @@ DEFAULT_LANGUAGE_CODE="eng"
# TODO: This needs to be used in the glob, but I don't know how.
VIDEO_EXTENSIONS="mkv,mp4,avi"
typeset -A LANGUAGE_NAMES
LANGUAGE_NAMES=( \
'english' 'en' \
)
_mkvmerge_add_subtitles_mkvmerge () {
original_file="$1"
results_directory="$2"
@ -26,21 +31,61 @@ _mkvmerge_add_subtitles_mkvmerge () {
# TODO: Support the other patterns listed in the above comment.
video_basename="$1"
# Include subtitles without language codes, assuming $DEFAULT_LANGUAGE_CODE is correct.
# For example: [basename].srt
uncoded_subtitle_name="${original_file:r}.srt"
if [[ -f "$uncoded_subtitle_name" ]]; then
subtitle_options_array+=("--language" "0:${DEFAULT_LANGUAGE_CODE}" "$uncoded_subtitle_name")
echo "Found uncoded subtitle file ${uncoded_subtitle_name}, assuming \
${DEFAULT_LANGUAGE_CODE}."
fi
# Include subtitles with language codes in their filenames.
# For example [basename].[language code].srt
coded_subtitle_files=(${original_file:r}.*.srt(N))
if [[ ! -z $coded_subtitle_files ]]; then
for fname in "$coded_subtitle_files"; do
for fname in $coded_subtitle_files; do
language_code="${${fname:r}:e}"
subtitle_options_array+=("--language" "0:${language_code}" "$fname")
echo "Found coded subtitle file ${fname} for language ${language_code}."
done
fi
# Include subtitles without language codes, assuming $DEFAULT_LANGUAGE_CODE is correct.
# For example: [basename].srt
uncoded_subtitle_name="${original_file:r}.srt"
if [[ -f "$uncoded_subtitle_name" ]]; then
subtitle_options_array+=("--language" "0:${DEFAULT_LANGUAGE_CODE}" "$uncoded_subtitle_name")
# Include subtitles in the Subs directory
named_subtitle_files=(${original_file:h}/Subs/*.srt(N))
if [[ ! -z $named_subtitle_files ]]; then
existing_language_codes=()
for fname in $named_subtitle_files; do
file_basename=${fname:t}
# determine language code from filenames like 2_English.srt
# This character soup does three things
# * #[0-9]*_ removes the preceding track number, such as 2_ or 13_
# * :r removes the file extension
# * :l makes it all lowercase
language_name="${${file_basename#[0-9]*_}:r:l}"
echo "Found subtitle file ${fname}."
if [[ $LANGUAGE_NAMES[$language_name] ]]; then
language_code=$LANGUAGE_NAMES[$language_name]
echo "Checking if subtitle file ${fname} is usable."
# TODO: This is absolutely an ugly way to do this, but this is what works.
if $(echo ${existing_language_codes} > grep ${language_code}); then
subtitle_options_array+=("--language" "0:${language_code}" "$fname")
existing_language_codes+=$language_code
echo "Found ${language_code} subtitles at ${fname}."
else
echo "Duplicate subtitle files for ${language_code}."
exit 1
fi
else
echo "Unknown language name ${language_name}."
exit 1
fi
done
fi
# Finally, actually mux all the subtitles in if there are any.
@ -48,7 +93,7 @@ _mkvmerge_add_subtitles_mkvmerge () {
echo "No subtitles found for file ${original_file}"
else
echo "Remuxing ${original_file}..."
mkvmerge --quiet -o "$partial_file" "$original_file" ${(@)subtitle_options_array} \
mkvmerge --quiet -o "$partial_file" "$original_file" ${^subtitle_options_array} \
|| rm "$partial_file"
echo "Done!"
Loading…
Cancel
Save