Compare commits

..

24 Commits

Author SHA1 Message Date
d19e60cfc3 Changed the worktree to one directory back (i.e. $HOME) and simplified the setup 2023-06-14 02:02:43 -04:00
0ee1e7666e Prep work before we use the new setup 2023-06-13 15:45:28 -04:00
c7845e62d9 Make moving lines easier in vim and change the tab listchar 2023-06-13 14:56:35 -04:00
2a57ce8837 Rename stuff in vimrc 2023-06-12 22:51:42 -04:00
a529cd6560 Improve vimrc - abbreviation fix, some leader stuff 2023-06-12 22:50:02 -04:00
589abb9e46 Tweak whisper core/thread count 2023-06-12 22:49:45 -04:00
6df4a1e506 Add a registry key for disabling the Windows platform binary table 2023-06-09 17:20:39 -04:00
10c6e8e06c Update aliases 2023-06-09 17:20:24 -04:00
f70bc8b9cd Alias tweaks around video dl 2023-06-06 15:48:43 -04:00
dad6be889f More transcription script improvements 2023-06-05 17:12:16 -04:00
e979d1094c Set whisper thread count based on the model 2023-06-05 14:18:44 -04:00
ce1599466e Update aliases with some audio transcription stuff 2023-06-05 01:23:47 -04:00
e5e8f309e5 Improve transcribe api and add alias to transcribe twitch stream downloads 2023-06-04 14:40:45 -04:00
8ff9c338b5 Add vimrc function for searching specific extensions 2023-06-03 17:42:42 -04:00
173bda9eb0 Add scripts for audio transcription using whisper.cpp 2023-06-03 17:42:30 -04:00
06bbc0c995 Use absolute path to build.jai 2023-06-03 16:22:13 -04:00
f19e84e1a5 Change some vim mappings 2023-05-21 18:02:21 -04:00
1a46964bd7 Tweak Windows key remapping notes 2023-05-16 12:05:46 -04:00
0e91857946 Note on disabling Cortana 2023-05-14 21:31:22 -04:00
bb31351404 Explain how to map caps to ctrl for wireless keyboards connected to a Steam Link 2023-05-12 18:35:13 -04:00
7b031d3127 More tweaks to the vimrc run function 2023-05-10 14:56:43 -04:00
c05131d38f Move a vimrc function so that it can be called in a private vimrc 2023-05-10 13:06:52 -04:00
418d1ae956 Fix typo in vimrc 2023-05-08 23:34:04 -04:00
e614936478 Add a trim video script that is more accurate 2023-05-07 16:11:49 -04:00
143 changed files with 1008 additions and 530 deletions

View File

@@ -189,7 +189,7 @@ alias ls='ls -F --color'
alias l='ls -lh' alias l='ls -lh'
alias ll='ls -lha' alias ll='ls -lha'
alias aliases='vim ~/.dotfiles/aliases' alias aliases='vim ~/.aliases'
alias al='aliases' alias al='aliases'
if [[ "${platform,,}" == *'ming'* ]]; then if [[ "${platform,,}" == *'ming'* ]]; then
@@ -212,7 +212,7 @@ check_signature() {
local sig_file="$4" local sig_file="$4"
if [[ $hashes_file == "" || $pem_file == "" || $sig_file == "" ]]; then if [[ $hashes_file == "" || $pem_file == "" || $sig_file == "" ]]; then
error "Usage: $0 <hashes file (e.g. sha512 hashes)> <pem file> <sig file>" error "Usage: <hashes file (e.g. sha512 hashes)> <pem file> <sig file>"
return return
fi fi
@@ -278,6 +278,8 @@ custom_grep() {
local include_list=("$@") local include_list=("$@")
local include_arg="" local include_arg=""
if [[ $include_list != "" ]]; then if [[ $include_list != "" ]]; then
# We're looping like this instead of for var in "$@", because that way of looping is affecting
# my shell environment. Very strange!
for i in "${include_list[@]}"; do for i in "${include_list[@]}"; do
include_arg+="--include=\*${i} " include_arg+="--include=\*${i} "
done done
@@ -311,9 +313,13 @@ alias grep-dev='grep_dev'
COMPRESSION_ON=1 COMPRESSION_ON=1
COMPRESSION_OFF=0 COMPRESSION_OFF=0
SHORTNAME_ON=1 SHORTNAME_ON=1
SHORTNAME_OFF=0 SHORTNAME_OFF=0
TRANSCRIBE_ON=1
TRANSCRIBE_OFF=0
make_vid_dir_and_cd_into() { make_vid_dir_and_cd_into() {
local url="$1" local url="$1"
local dir_name="$2" local dir_name="$2"
@@ -344,73 +350,71 @@ make_vid_dir_and_cd_into() {
return 0 return 0
} }
function my_transcribe_video() {
file="$1"
output="$2"
if [[ $file == "" ]]; then
printf "Usage: <input video> <optional output name>\n"
return
fi
if [[ $output == "" ]]; then
output="${1%.*}" # just use the input name without the extension.
fi
# Tiny is fast and semi-accurate, so whatever.
# Base is pretty good overall. It has good punctuation inserting and
# catches most words. Small and medium can do better word detection at
# times, but suffer from bad punctuation. Medium is particularly bad and
# not adding commas and periods.
transcribe-video "$file" "$output" tiny base
}
function my_transcribe_video_all_models() {
file="$1"
output="$2"
if [[ $file == "" ]]; then
printf "Usage: <input video> <optional output name>\n"
return
fi
if [[ $output == "" ]]; then
output="${1%.*}" # just use the input name without the extension.
fi
transcribe-video "$file" "$output" tiny base small medium
}
# Download YouTube videos. Note that yt-dlp downloads a lot faster than streamlink. # Download YouTube videos. Note that yt-dlp downloads a lot faster than streamlink.
download_youtube_vid() { download_youtube_vid() {
local format="$1" local format="$1"
local shortname="$2" local shortname="$2"
local make_folder="$3" local transcribe="$3"
local url="$4"
shift 4 local make_folder="$4"
local url="$5"
shift 5
local opts="$@" local opts="$@"
if [[ $url == "" ]]; then if [[ $url == "" ]]; then
error "Usage: $0 <make folder?> <url> <optional args>" error "Usage: <make folder?> <url> <optional args>"
return return
fi fi
if [[ $format == "" ]]; then if [[ $shortname == "1" || $transcribe == "1" ]]; then
printf "${BOLD}No format given; using best available.${NORMAL}\n" printf "${BOLD}Downloading Youtube vid "
# Download best mp4 video and best m4a audio, then merge. if [[ $shortname == "1" ]]; then printf "| ${YELLOW}using short name${NORMAL}${BOLD} "; fi
format="bv*[ext=mp4]+ba[ext=m4a]" if [[ $transcribe == "1" ]]; then printf "| ${YELLOW}audio transcription on${NORMAL}${BOLD} "; fi
opts+=" --merge-output-format mp4" printf "\n\n${NORMAL}"
fi
opts+=" --write-subs --sub-lang en --embed-subs"
if [[ $make_folder == "1" ]]; then
make_vid_dir_and_cd_into $url ""
if [[ $? -ne 0 ]]; then
return
fi
fi
if [[ $shortname -eq 0 ]]; then
local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-yt-%(id)s.%(ext)s"
else else
local name_format="%(upload_date>%Y-%m-%d)s-shortname-yt-%(id)s.%(ext)s" printf "${BOLD}Downloading Youtube vid\n\n${NORMAL}"
fi fi
local cmd="yt-dlp.exe -f $format -o \"$name_format\" $opts $url"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
# Removing any trailing subtitle files
rm *.vtt *.srt 2>/dev/null
if [[ $make_folder == "1" ]]; then
cd ..
fi
}
# Download YouTube video and flip horizontally.
download_youtube_vid_and_hflip() {
local format="$1"
local make_folder="$2"
local url="$3"
shift 3
local opts="$@"
if [[ $url == "" ]]; then
error "Usage: $0 <make folder?> <url> <optional args>"
return
fi
if [[ $format == "" ]]; then if [[ $format == "" ]]; then
printf "${BOLD}No format given; using best available.${NORMAL}\n" printf "${BOLD}No format given; using best available.${NORMAL}\n"
# Download best mp4 video and best m4a audio, then merge. # Download best mp4 video.
format="bv*[ext=mp4]+ba[ext=m4a]" format="bv*[ext=mp4]+ba[ext=m4a]"
opts+=" --merge-output-format mp4"
fi fi
opts+=" --write-sub --sub-lang en --embed-subs" # We're assuming we'll always have an mp4 video only and audio track to merge.
opts+=" --merge-output-format mp4 --write-subs --sub-lang en --embed-subs"
if [[ $make_folder == "1" ]]; then if [[ $make_folder == "1" ]]; then
make_vid_dir_and_cd_into $url "" make_vid_dir_and_cd_into $url ""
@@ -419,21 +423,37 @@ download_youtube_vid_and_hflip() {
fi fi
fi fi
local filename=$(yt-dlp.exe --get-filename -f $format -o "%(upload_date>%Y-%m-%d)s-%(title)s-yt-%(id)s.%(ext)s" $url) if [[ $shortname == "0" ]]; then
local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-yt-%(id)s"
else
local name_format="%(upload_date>%Y-%m-%d)s-shortname-yt-%(id)s"
fi
# Get the video filename.
local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
printf "filename: $filename\n"
# Download
local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url" local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string. eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
error=$?
if [[ $error -ne 0 ]]; then
error "Error: Failed to download '$url'"
if [[ $make_folder == "1" ]]; then cd ..; fi
return
fi
# Removing any trailing subtitle files # Removing any trailing subtitle files
rm *.vtt *.srt 2>/dev/null rm *.vtt *.srt 2>/dev/null
# Flip if [[ $transcribe == "1" ]]; then
ffmpeg -i "$filename" -vf hflip -c:a copy "copy_${filename}" my_transcribe_video "$filename"
mv "copy_${filename}" "$filename"
if [[ $make_folder == "1" ]]; then
cd ..
fi fi
if [[ $make_folder == "1" ]]; then cd ..; fi
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
download_youtube_playlist() { download_youtube_playlist() {
@@ -444,9 +464,12 @@ download_youtube_playlist() {
local opts="$@" local opts="$@"
if [[ $url == "" ]]; then if [[ $url == "" ]]; then
error "Usage: $0 <url> <directory name (optional)> <optional args>" error "Usage: <url> <directory name (optional)> <optional args>"
return return
fi fi
printf "${BOLD}Downloading Youtube playlist\n\n${NORMAL}"
if [[ $format == "" ]]; then if [[ $format == "" ]]; then
printf "${BOLD}No format given; using best available.${NORMAL}\n" printf "${BOLD}No format given; using best available.${NORMAL}\n"
# Download best mp4 video and best m4a audio, then merge. # Download best mp4 video and best m4a audio, then merge.
@@ -469,7 +492,56 @@ download_youtube_playlist() {
# Removing any trailing subtitle files # Removing any trailing subtitle files
rm *.vtt *.srt 2>/dev/null rm *.vtt *.srt 2>/dev/null
cd .. if [[ $dir_name == "1" ]]; then cd ..; fi
printf "${BOLD}Finished downloading the playlist\n${NORMAL}"
}
download_youtube_playlist_list() {
local url="$1"
local output_name="$2"
shift 2
local opts="$@"
if [[ $url == "" || $output_name == "" ]]; then
error "Usage: <url> <output name> <optional args>"
return
fi
printf "${BOLD}Downloading Youtube playlist video list\n\n${NORMAL}"
local cmd="yt-dlp.exe --ignore-errors -O \"%(playlist_index)s-%(title)s--%(id)s\" --skip-download $opts $url"
eval $cmd 1>"${output_name}.txt" # Need to eval in order to preserve the quotes wrapping the filename format string.
printf "${BOLD}Finished downloading the playlist video list\n${NORMAL}"
}
download_youtube_uploads_list() {
local include_descriptions="$1"
local url="$2"
local output_name="$3"
shift 3
local opts="$@"
if [[ $url == "" || $output_name == "" ]]; then
error "Usage: <url> <output name> <optional args>"
return
fi
local cmd=""
if [[ $include_descriptions == "1" ]]; then
printf "${BOLD}Downloading Youtube uploads list with descriptions\n\n${NORMAL}"
cmd="yt-dlp.exe --ignore-errors -O \"@@@ %(video_autonumber)s-%(upload_date>%Y-%m-%d)s--%(title)s--%(id)s\" --skip-download --get-description $opts $url"
else
printf "${BOLD}Downloading Youtube uploads list\n\n${NORMAL}"
cmd="yt-dlp.exe --ignore-errors -O \"%(video_autonumber)s-%(upload_date>%Y-%m-%d)s--%(title)s--%(id)s\" --skip-download $opts $url"
fi
eval $cmd 1>"${output_name}.txt" # Need to eval in order to preserve the quotes wrapping the filename format string.
printf "${BOLD}Finished downloading the upload list\n${NORMAL}"
} }
# Download Twitch chat transcript # Download Twitch chat transcript
@@ -484,6 +556,8 @@ actually_download_twitch_chat() {
else else
error "Video doesn't have a chat transcript." error "Video doesn't have a chat transcript."
fi fi
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
download_twitch_chat() { download_twitch_chat() {
@@ -493,7 +567,7 @@ download_twitch_chat() {
local opts="$@" local opts="$@"
if [[ $url == "" ]]; then if [[ $url == "" ]]; then
error "Usage: $0 <url>" error "Usage: <url>"
return return
fi fi
@@ -504,11 +578,9 @@ download_twitch_chat() {
fi fi
fi fi
actually_download_twitch_chat $url "$(yt-dlp.exe --get-filename -o "%(upload_date>%Y-%m-%d)s-%(title)s-tw-%(id)s" $opts $url)" actually_download_twitch_chat $url "$(yt-dlp.exe --get-filename -o "%(upload_date>%Y-%m-%d)s-%(title)s-tw-%(id)s.chat" $opts $url)"
if [[ $make_folder == "1" ]]; then if [[ $make_folder == "1" ]]; then cd ..; fi
cd ..
fi
} }
# Download Twitch videos, both VODs and live streams. Pass a Twitch account URL to download a live stream. # Download Twitch videos, both VODs and live streams. Pass a Twitch account URL to download a live stream.
@@ -526,13 +598,14 @@ download_twitch_vid() {
local format="$1" local format="$1"
local shortname="$2" local shortname="$2"
local compress="$3" local compress="$3"
local make_folder="$4" local transcribe="$4"
local url="$5" local make_folder="$5"
shift 5 local url="$6"
shift 6
local opts="$@" local opts="$@"
if [[ $url == "" ]]; then if [[ $url == "" ]]; then
error "Usage: $0 <make folder?> <url> <optional args>" error "Usage: <make folder?> <url> <optional args>"
return return
fi fi
@@ -547,10 +620,14 @@ download_twitch_vid() {
printf "${BOLD}Subscriber VOD. Will use yt-dlp to download.${NORMAL}\n" printf "${BOLD}Subscriber VOD. Will use yt-dlp to download.${NORMAL}\n"
fi fi
if [[ $compress -eq 0 ]]; then if [[ $shortname == "1" || $compress == "1" || $transcribe == "1" ]]; then
printf "${BOLD}Downloading Twitch vid with no compression.${NORMAL}\n" printf "${BOLD}Downloading Twitch vid "
if [[ $shortname == "1" ]]; then printf "| ${YELLOW}using short name${NORMAL}${BOLD} "; fi
if [[ $compress == "1" ]]; then printf "| ${YELLOW}compression on${NORMAL}${BOLD} "; fi
if [[ $transcribe == "1" ]]; then printf "| ${YELLOW}audio transcription on${NORMAL}${BOLD} "; fi
printf "\n\n${NORMAL}"
else else
printf "${BOLD}Downloading Twitch vid with compression.${NORMAL}\n" printf "${BOLD}Downloading Twitch vid\n\n${NORMAL}"
fi fi
local yt_dlp_format="" local yt_dlp_format=""
@@ -573,7 +650,7 @@ download_twitch_vid() {
fi fi
fi fi
if [[ $shortname -eq 0 ]]; then if [[ $shortname == "0" ]]; then
local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-tw-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-tw-%(id)s"
else else
local name_format="%(upload_date>%Y-%m-%d)s-shortname-tw-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-shortname-tw-%(id)s"
@@ -583,59 +660,72 @@ download_twitch_vid() {
actually_download_twitch_chat $url "$(yt-dlp.exe --get-filename -o "$name_format" $opts $url)" actually_download_twitch_chat $url "$(yt-dlp.exe --get-filename -o "$name_format" $opts $url)"
# Get the video filename. # Get the video filename.
local filename=$(yt-dlp.exe --get-filename -o "$name_format.%(ext)s" $opts $url) local filename=$(yt-dlp.exe --get-filename -f $yt_dlp_format -o "$name_format.%(ext)s" $opts $url)
# Download # Download
if [[ $subscriber_vod -eq 0 ]]; then if [[ $subscriber_vod == "0" ]]; then
local cmd="streamlink.exe --twitch-low-latency --twitch-disable-ads --twitch-disable-hosting --force --force-progress $opts $url $streamlink_format -O | ffmpeg -i pipe:0 -c copy \"$filename\"" local cmd="streamlink.exe --twitch-low-latency --twitch-disable-ads --twitch-disable-hosting --force --force-progress $opts $url $streamlink_format -O | ffmpeg -i pipe:0 -c copy \"$filename\""
else else
local cmd="yt-dlp.exe -f $yt_dlp_format -o \"$filename\" $opts $url" local cmd="yt-dlp.exe -f $yt_dlp_format -o \"$filename\" $opts $url"
fi fi
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string. printf "${YELLOW}${BOLD}Downloading video\n${NORMAL}"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
error=$? error=$?
if [[ $error -eq 0 ]]; then
if [[ $compress -eq 1 ]]; then if [[ $error -ne 0 ]]; then
local temp_name="temp_${RANDOM}"
# 0=cpu, 1=gpu
compress-video "$filename" "$temp_name" 0
extension="${filename##*.}"
mv "$filename" "orig_$filename"
mv $temp_name.$extension "$filename"
printf "${BOLD}Make sure to delete the original video file${NORMAL}\n"
fi
else
error "Error: Failed to download '$url'" error "Error: Failed to download '$url'"
if [[ $make_folder == "1" ]]; then cd ..; fi
return
fi fi
if [[ $make_folder == "1" ]]; then if [[ $compress == "1" ]]; then
cd .. local temp_name="temp_${RANDOM}"
# 0=cpu, 1=gpu
compress-video "$filename" "$temp_name" 0
extension="${filename##*.}"
mv "$filename" "orig_$filename"
mv $temp_name.$extension "$filename"
printf "${BOLD}Make sure to delete the original video file\n${NORMAL}"
fi fi
if [[ $transcribe == "1" ]]; then
my_transcribe_video "$filename"
fi
if [[ $make_folder == "1" ]]; then cd ..; fi
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
# Download Vimeo videos. # Download Vimeo videos.
# Can download an embedded vid. You might need to save the site cookies if the vid is behind a paywall. # Can download an embedded vid. You might need to save the site cookies if the vid is behind a paywall.
# e.g. yt-dlp.exe -F --cookies cookies.txt --referer https://gillyandkeeves.tv https://player.vimeo.com/video/756941969 # e.g. --cookies cookies.txt --referer https://gillyandkeeves.tv https://player.vimeo.com/video/756941969
# The vid ID can be found by looking at the embed's iframe src attribute. # The vid ID can be found by looking at the embed's iframe src attribute.
download_vimeo_vid() { download_vimeo_vid() {
local format="$1" local shortname="$1"
local shortname="$2" local compress="$2"
local compress="$3" local transcribe="$3"
local make_folder="$4" local format="$4"
local url="$5" local make_folder="$5"
local url="$6"
shift 5 shift 5
local opts="$@" local opts="$@"
if [[ $url == "" ]]; then if [[ $format == "" || $url == "" ]]; then
error "Usage: $0 <make folder?> <url> <optional args>" error "Usage: <format> <make folder?> <url> <optional args>"
return return
fi fi
if [[ $compress -eq 0 ]]; then if [[ $shortname == "1" || $compress == "1" || $transcribe == "1" ]]; then
printf "${BOLD}Downloading Vimeo vid with no compression.${NORMAL}\n" printf "${BOLD}Downloading Vimeo vid "
if [[ $shortname == "1" ]]; then printf "| ${YELLOW}using short name${NORMAL}${BOLD} "; fi
if [[ $compress == "1" ]]; then printf "| ${YELLOW}compression on${NORMAL}${BOLD} "; fi
if [[ $transcribe == "1" ]]; then printf "| ${YELLOW}audio transcription on${NORMAL}${BOLD} "; fi
printf "\n\n${NORMAL}"
else else
printf "${BOLD}Downloading Vimeo vid with compression.${NORMAL}.\n" printf "${BOLD}Downloading Vimeo vid\n\n${NORMAL}"
fi fi
if [[ $make_folder == "1" ]]; then if [[ $make_folder == "1" ]]; then
@@ -645,7 +735,7 @@ download_vimeo_vid() {
fi fi
fi fi
if [[ $shortname -eq 0 ]]; then if [[ $shortname == "0" ]]; then
local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-vimeo-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-vimeo-%(id)s"
else else
local name_format="%(upload_date>%Y-%m-%d)s-shortname-vimeo-%(id)s" local name_format="%(upload_date>%Y-%m-%d)s-shortname-vimeo-%(id)s"
@@ -659,7 +749,7 @@ download_vimeo_vid() {
error=$? error=$?
if [[ $error -eq 0 ]]; then if [[ $error -eq 0 ]]; then
if [[ $compress -eq 1 ]]; then if [[ $compress == "1" ]]; then
local temp_name="temp_${RANDOM}" local temp_name="temp_${RANDOM}"
# 0=cpu, 1=gpu # 0=cpu, 1=gpu
compress-video "$filename" "$temp_name" 0 compress-video "$filename" "$temp_name" 0
@@ -670,11 +760,17 @@ download_vimeo_vid() {
fi fi
else else
error "Error: Failed to download '$url'" error "Error: Failed to download '$url'"
if [[ $make_folder == "1" ]]; then cd ..; fi
return
fi fi
if [[ $make_folder == "1" ]]; then if [[ $transcribe == "1" ]]; then
cd .. my_transcribe_video "$filename"
fi fi
if [[ $make_folder == "1" ]]; then cd ..; fi
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
# Download Twitter videos. # Download Twitter videos.
@@ -685,7 +781,7 @@ download_twitter_vid() {
local vid_name="$4" local vid_name="$4"
if [[ $url == "" ]]; then if [[ $url == "" ]]; then
error "Usage: $0 <make folder?> <url> <optional filename> <optional args>" error "Usage: <make folder?> <url> <optional filename> <optional args>"
return return
fi fi
@@ -723,9 +819,64 @@ download_twitter_vid() {
error "Error: Failed to download '$url'" error "Error: Failed to download '$url'"
fi fi
if [[ $make_folder == "1" ]]; then if [[ $make_folder == "1" ]]; then cd ..; fi
cd ..
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
}
# Download Instagram videos.
download_instagram_vid() {
local transcribe="$1"
local make_folder="$2"
local url="$3"
local vid_name="$4"
if [[ $url == "" ]]; then
error "Usage: <make folder?> <url> <optional filename> <optional args>"
return
fi fi
printf "${BOLD}Downloading Instagram vid.${NORMAL}\n"
if [[ $vid_name == "" ]]; then
local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-ig-%(id)s"
local opts=""
else
local name_format="%(upload_date>%Y-%m-%d)s-${vid_name}-ig-%(id)s"
shift 4
local opts="$@"
fi
if [[ $make_folder == "1" ]]; then
make_vid_dir_and_cd_into $url $vid_name $opts
if [[ $? -ne 0 ]]; then
return
fi
fi
format="b" # best available
# Download the video.
local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
eval $cmd # Need to eval in order to preserve the quotes wrapping the filename format string.
error=$?
if [[ $error -eq 1 ]]; then
error "Error: Failed to download '$url'"
if [[ $make_folder == "1" ]]; then cd ..; fi
return
fi
if [[ $transcribe == "1" ]]; then
transcribe "$filename"
fi
if [[ $make_folder == "1" ]]; then cd ..; fi
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
# Download MP4 video. # Download MP4 video.
@@ -734,7 +885,7 @@ download_mp4() {
local filename="$2" local filename="$2"
if [[ $url == "" || $filename == "" ]]; then if [[ $url == "" || $filename == "" ]]; then
error "Usage: $0 <url> <filename>" error "Usage: <url> <filename>"
return return
fi fi
@@ -757,7 +908,7 @@ download_from_m3u8() {
local filename="$2" local filename="$2"
if [[ $m3u8_path == "" || $filename == "" ]]; then if [[ $m3u8_path == "" || $filename == "" ]]; then
error "Usage: $0 <m3u8 path> <filename>" error "Usage: <m3u8 path> <filename>"
return return
fi fi
@@ -772,93 +923,129 @@ download_from_m3u8() {
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n" printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
} }
# Download Instagram video and flip horizontally.
download_instagram_vid_and_hflip() {
local url="$1"
local filename="$2"
if [[ $url == "" || $filename == "" ]]; then
error "Usage: $0 <url> <filename>"
return
fi
temp_name="temp_${RANDOM}.mp4"
printf "${BOLD}Downloading: ${YELLOW}$filename${NORMAL}\n"
curl "$url" -o $temp_name
if [[ $? -ne 0 ]]; then
error "Error: failed to download."
return
fi
# Flip
ffmpeg -i $temp_name -vf hflip -c:a copy "copy_$temp_name"
mv copy_${temp_name} "$filename.mp4"
rm $temp_name
}
#-------------------------------------------------
# YouTube Vid DL # YouTube Vid DL
alias yt='download_youtube_vid "" $SHORTNAME_OFF' #-------------------------------------------------
alias yt-shortname='download_youtube_vid "" $SHORTNAME_ON' alias yt-list='download_youtube_uploads_list 0 '
alias yt-1080='download_youtube_vid "137+140" $SHORTNAME_OFF' alias yt-list-desc='download_youtube_uploads_list 1 '
alias yt-1080-shortname='download_youtube_vid "137+140" $SHORTNAME_ON'
alias yt-720='download_youtube_vid "136+140" $SHORTNAME_OFF'
alias yt-720-shortname='download_youtube_vid "136+140" $SHORTNAME_ON'
alias yt-playlist='download_youtube_playlist ""' alias yt='download_youtube_vid "" $SHORTNAME_OFF $TRANSCRIBE_OFF'
alias yt-shortname='download_youtube_vid "" $SHORTNAME_ON $TRANSCRIBE_OFF'
alias yt-1080='download_youtube_vid "137+140" $SHORTNAME_OFF $TRANSCRIBE_OFF'
alias yt-1080-shortname='download_youtube_vid "137+140" $SHORTNAME_ON $TRANSCRIBE_OFF'
alias yt-720='download_youtube_vid "136+140" $SHORTNAME_OFF $TRANSCRIBE_OFF'
alias yt-720-shortname='download_youtube_vid "136+140" $SHORTNAME_ON $TRANSCRIBE_OFF'
#TRANSCRIPTION ON
alias ytt='download_youtube_vid "" $SHORTNAME_OFF $TRANSCRIBE_ON'
alias yt-shortname-t='download_youtube_vid "" $SHORTNAME_ON $TRANSCRIBE_ON'
alias yt-1080-t='download_youtube_vid "137+140" $SHORTNAME_OFF $TRANSCRIBE_ON'
alias yt-1080-shortname-t='download_youtube_vid "137+140" $SHORTNAME_ON $TRANSCRIBE_ON'
alias yt-720-t='download_youtube_vid "136+140" $SHORTNAME_OFF $TRANSCRIBE_ON'
alias yt-720-shortname-t='download_youtube_vid "136+140" $SHORTNAME_ON $TRANSCRIBE_ON'
#---------------------------
alias yt-playlist='download_youtube_playlist ""'
alias yt-playlist-list='download_youtube_playlist_list '
alias yt-playlist-1080='download_youtube_playlist "137+140"' alias yt-playlist-1080='download_youtube_playlist "137+140"'
alias yt-playlist-720='download_youtube_playlist "136+140"' alias yt-playlist-720='download_youtube_playlist "136+140"'
alias yt-playlist-tiny='download_youtube_playlist "160+140"' alias yt-playlist-tiny='download_youtube_playlist "160+140"'
alias yt-audio='yt-dlp.exe -f "140"' alias yt-audio='yt-dlp.exe -f "140"'
alias yt-and-hflip='download_youtube_vid_and_hflip "137+140"' # 1080p
#-------------------------------------------------
# Twitch Vid DL # Twitch Vid DL
alias tw='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_OFF' #-------------------------------------------------
alias tw-compressed='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_ON'
alias tw-shortname='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_OFF'
alias tw-shortname-compressed='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_ON'
alias tw-custom='download_twitch_vid '
alias tw-chat='download_twitch_chat' alias tw-chat='download_twitch_chat'
alias tw-1080='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_OFF' alias tw='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_OFF $TRANSCRIBE_OFF'
alias tw-1080-compressed='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_ON' alias tw-compressed='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080-shortname='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_OFF' alias tw-shortname='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_OFF $TRANSCRIBE_OFF'
alias tw-1080-shortname-compressed='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_ON' alias tw-shortname-compressed='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-source='download_twitch_vid "Source" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-custom='download_twitch_vid '
#TRANSCRIPTION ON
alias twt='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_OFF $TRANSCRIBE_ON'
alias tw-compressed-t='download_twitch_vid "" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-shortname-t='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_OFF $TRANSCRIBE_ON'
alias tw-shortname-compressed-t='download_twitch_vid "" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-source-t='download_twitch_vid "Source" "Source" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p60='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_OFF' #1080p
alias tw-1080p50='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_OFF' alias tw-1080='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p60-compressed='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_ON' alias tw-1080-compressed='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p50-compressed='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_ON' alias tw-1080-shortname='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p60-shortname='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_OFF' alias tw-1080-shortname-compressed='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p50-shortname='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_OFF' #TRANSCRIPTION ON
alias tw-1080p60-shortname-compressed='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_ON' alias tw-1080-t='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p50-shortname-compressed='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_ON' alias tw-1080-compressed-t='download_twitch_vid "1080" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080-shortname-t='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080-shortname-compressed-t='download_twitch_vid "1080" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-720='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_OFF' #1080p60/50
alias tw-720-compressed='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_ON' alias tw-1080p60='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-720-shortname='download_twitch_vid "720p" $SHORTNAME_ON $COMPRESSION_OFF' alias tw-1080p50='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-720p60='download_twitch_vid "720p60" $SHORTNAME_OFF $COMPRESSION_OFF' alias tw-1080p60-compressed='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-720p60-shortname='download_twitch_vid "720p60" $SHORTNAME_ON $COMPRESSION_OFF' alias tw-1080p50-compressed='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p60-shortname='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p50-shortname='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p60-shortname-compressed='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-1080p50-shortname-compressed='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
#TRANSCRIPTION ON
alias tw-1080p60-t='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p50-t='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p60-compressed-t='download_twitch_vid "1080p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p50-compressed-t='download_twitch_vid "1080p50" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p60-shortname-t='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p50-shortname-t='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p60-shortname-compressed-t='download_twitch_vid "1080p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-1080p50-shortname-compressed-t='download_twitch_vid "1080p50" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-4k='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_OFF' #720p
alias tw-4k-compressed='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_ON' alias tw-720='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-4k-shortname='download_twitch_vid "2160p" $SHORTNAME_ON $COMPRESSION_OFF' alias tw-720-compressed='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-4k-shortname-compressed='download_twitch_vid "2160p" $SHORTNAME_ON $COMPRESSION_ON' alias tw-720-shortname='download_twitch_vid "720p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-720p60='download_twitch_vid "720p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-720p60-shortname='download_twitch_vid "720p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
#TRANSCRIPTION ON
alias tw-720-t='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-720-compressed-t='download_twitch_vid "720p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-720-shortname-t='download_twitch_vid "720p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-720p60-t='download_twitch_vid "720p60" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-720p60-shortname-t='download_twitch_vid "720p60" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-source='download_twitch_vid "Source" $SHORTNAME_OFF $COMPRESSION_OFF' #4k
alias tw-4k='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-4k-compressed='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-4k-shortname='download_twitch_vid "2160p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
alias tw-4k-shortname-compressed='download_twitch_vid "2160p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_OFF'
#TRANSCRIPTION ON
alias tw-4k-t='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-4k-compressed-t='download_twitch_vid "2160p" $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-4k-shortname-t='download_twitch_vid "2160p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
alias tw-4k-shortname-compressed-t='download_twitch_vi "2160p" $SHORTNAME_ON $COMPRESSION_ON $TRANSCRIBE_ON'
#-------------------------------------------------
# Vimeo Vid DL # Vimeo Vid DL
alias vimeo='download_vimeo_vid "Original" $SHORTNAME_OFF $COMPRESSION_OFF' #-------------------------------------------------
alias vimeo-compressed='download_vimeo_vid "Original" $SHORTNAME_OFF $COMPRESSION_ON' alias vimeo='download_vimeo_vid $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias vimeo-t='download_vimeo_vid $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
alias vimeo-compressed='download_vimeo_vid $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_OFF'
alias vimeo-compressed-t='download_vimeo_vid $SHORTNAME_OFF $COMPRESSION_ON $TRANSCRIBE_ON'
#-------------------------------------------------
# Instagram Vid DL # Instagram Vid DL
alias ig-download-and-hflip='download_instagram_vid_and_hflip ' #-------------------------------------------------
alias ig='download_instagram_vid $TRANSCRIBE_OFF'
alias igt='download_instagram_vid $TRANSCRIBE_ON'
#-------------------------------------------------
# Twitter Vid DL # Twitter Vid DL
alias twt='download_twitter_vid "" ' #-------------------------------------------------
alias twitter='download_twitter_vid "" '
#-------------------------------------------------
# Misc # Misc
#-------------------------------------------------
alias download-mp4='download_mp4' alias download-mp4='download_mp4'
alias download-from-m3u8='download_from_m3u8' alias download-from-m3u8='download_from_m3u8'
@@ -949,7 +1136,7 @@ alias gaup='git add --update -p'
alias gb='git branch -v' alias gb='git branch -v'
alias gbb='git bisect bad' alias gbb='git bisect bad'
alias gbd='git branch -D' alias gbd='git branch -D'
alias gbdr='git branch -Dr' alias gbdr='git branch -Dr' # Delete a remote tracking branch; useful when the remote no longer exists and branch pruning isn't removing the lingering tracking branches.
alias gbg='git bisect good' alias gbg='git bisect good'
alias gbl='git branch --all' alias gbl='git branch --all'
alias gblm='git blame -wMC' alias gblm='git blame -wMC'
@@ -1050,10 +1237,11 @@ alias gsp3='git stash pop stash@{3}'
alias gsp4='git stash pop stash@{4}' alias gsp4='git stash pop stash@{4}'
alias gsp5='git stash pop stash@{6}' alias gsp5='git stash pop stash@{6}'
alias gsp6='git stash pop stash@{7}' alias gsp6='git stash pop stash@{7}'
alias gt='git tag -s' # Signed alias gt='git tag' # Unsigned
alias gta='git tag -a' alias gta='git tag -a'
alias gtd='git tag -d' alias gtd='git tag -d'
alias gtl='git tag -l' alias gtl='git tag -l'
alias gts='git tag -s' # Signed
alias gx='git reset --hard' alias gx='git reset --hard'
alias gxx='git reset --hard HEAD~1' alias gxx='git reset --hard HEAD~1'
alias gxom='git reset --hard origin/master' alias gxom='git reset --hard origin/master'

View File

View File

@@ -13,16 +13,20 @@ esac
export PLATFORM=$platform export PLATFORM=$platform
export PLATFORM_OS=$platform_os export PLATFORM_OS=$platform_os
test -f "$HOME/.env.platform" && . "$HOME/.env.platform" os_lower="${platform_os,,}"
test -f "$HOME/dotfiles/${os_lower}/env.platform" && . "$HOME/dotfiles/${os_lower}/env.platform"
test -f "$HOME/.env.common-pre" && . "$HOME/.env.common-pre" test -f "$HOME/.env.common-pre" && . "$HOME/.env.common-pre"
test -f "$HOME/.env.private" && . "$HOME/.env.private" test -f "$HOME/.env.private" && . "$HOME/.env.private"
test -f "$HOME/.env.common-post" && . "$HOME/.env.common-post" test -f "$HOME/.env.common-post" && . "$HOME/.env.common-post"
test -f "$HOME/.aliases" && . "$HOME/.aliases" test -f "$HOME/.aliases" && . "$HOME/.aliases"
test -f "$HOME/.aliases.common" && . "$HOME/.aliases.common" test -f "$HOME/.aliases.common" && . "$HOME/.aliases.common"
test -f "$HOME/.aliases.private" && . "$HOME/.aliases.private" test -f "$HOME/.aliases.private" && . "$HOME/.aliases.private"
if [[ $_MC_SET_ENV_PATH -ne 1 ]]; then if [[ $_MC_SET_ENV_PATH -ne 1 ]]; then
test -d "$HOME/bin" && export PATH=$HOME/bin/:$PATH test -d "$HOME/bin" && export PATH=$HOME/bin/:$PATH
#TODO: remove this
test -d "$HOME/.dotfiles/bin" && export PATH=$HOME/.dotfiles/bin/:$PATH test -d "$HOME/.dotfiles/bin" && export PATH=$HOME/.dotfiles/bin/:$PATH
fi fi

View File

@@ -1,5 +1,4 @@
[include] [include]
path = ~/.gitconfig.platform
path = ~/.gitconfig.private path = ~/.gitconfig.private
[init] [init]
defaultBranch = master defaultBranch = master
@@ -7,11 +6,25 @@
summary = true summary = true
tool = vimdiff tool = vimdiff
[core] [core]
excludesfile = ~/.gitignore excludesfile = ~/.gitignore.global
hookspath = ~/.git_hooks hookspath = ~/.git_hooks
preloadindex = true preloadindex = true
fscache = true fscache = true
editor = vim editor = vim
# I used to have this set to true, which would result in checked out files
# being converted to CRLF line endings and commits converting to LF. I'm
# tired of this conversion shit though so I'm turning it off and will be
# enforcing LF line endings via a combination of editorconfig and
# gitattribute files on a per-project basis. This should make sure that
# anyone contributing to my projects will be committing LF line endings.
# The only exception is that the gitattributes files will commit batch
# files with CRLF to avoid Windows glitches.
#
# I used these posts for reference:
# https://markentier.tech/posts/2021/10/autocrlf-true-considered-harmful/
# https://troyready.com/blog/git-windows-dont-convert-line-endings.html
#
autocrlf = false
[push] [push]
default = upstream default = upstream
[pull] [pull]

10
.gitignore vendored
View File

@@ -1,9 +1 @@
vim/.netrwhist *
vim/bundle/*
vim/plugged/*
vim/undo
vim/undo/*
vim/autoload/plug.vim.old
config/openbox/lxde-rc.xml
*.pyc
!bin

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "vim/bundle/Vundle.vim"]
path = vim/bundle/Vundle.vim
url = https://github.com/VundleVim/Vundle.vim.git

View File

View File

@@ -271,3 +271,7 @@ memcpy
strlen strlen
u8 u8
s64 s64
Sculpey
grey
googly
favour

BIN
.vim/spell/en.utf-8.add.spl Normal file

Binary file not shown.

View File

@@ -1,4 +1,4 @@
"----------------------------------------------------------------------------------------------------------------------- "-----------------------------------------------------------------------------------------------------------------------
" The config is chopped up into sections. Search for these headings to quickly jump to a particular section. " The config is chopped up into sections. Search for these headings to quickly jump to a particular section.
" "
" #0 GLOBALS " #0 GLOBALS
@@ -26,12 +26,12 @@ let s:uname = system("echo -n \"$(uname)\"")
let g:vim_dir = $HOME . "/.vim" let g:vim_dir = $HOME . "/.vim"
let mapleader="," let mapleader=","
function! IsWindows() fu! IsWindows()
if s:uname =~ "mingw" || s:uname =~ "msys" if s:uname =~ "mingw" || s:uname =~ "msys"
return 1 return 1
endif endif
return 0 return 0
endfunction endfu
if has('termguicolors') if has('termguicolors')
set termguicolors set termguicolors
@@ -40,12 +40,12 @@ if has('termguicolors')
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif endif
function! PrintError(msg) abort fu! PrintError(msg) abort
exec 'normal! \<Esc>' exec 'normal! \<Esc>'
echohl ErrorMsg echohl ErrorMsg
echomsg a:msg echomsg a:msg
echohl None echohl None
endfunction endfu
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -175,6 +175,33 @@ let g:campo_ctags_exclude = ['*.txt', '*.config', '.cache']
let g:campo_custom_ctags_args = "" let g:campo_custom_ctags_args = ""
" Set extra paths to use when searching for ctags files. By default the current
" directory is always checked. You can use this to combine tag lookups from
" different projects, e.g. set it to the Jai directory and you can look up
" current project tags and Jai module tags (the latter isn't needed if you
" have Jai module tags in your local file, which can be generated using the
" ctags module at compile time). Related, if you're generating jai ctags and
" the editor isn't finding module references then check if the current
" directory is set to where the tags file exists. I've been caught up by this
" because I have a build.jai in the root and my code in a src/ folder, so the
" tags file gets created in the root and won't be seen if I've cd'd into src/
" when editing code.
"
" This destructively overwrites the tags option value.
"
" Call this from a .vimrc.private or .lvimrc file, e.g.
" call g:SetExtraCtagsPaths([g:campo_jai_path.'/tags'])
"
" You can see what your ctags search list is set to in the editor with :echo &tags
fu! g:SetExtraCtagsPaths(paths_array)
let l:list = './tags,tags' " This is the default tags list set by vim.
for path in a:paths_array
let l:list .= ',' . path
endfor
let &tags=l:list
endfu
"################################################################################## "##################################################################################
" JAI " JAI
"################################################################################## "##################################################################################
@@ -210,12 +237,14 @@ Plug 'ctrlpvim/ctrlp.vim' " Fuzzy file, buffer, mru, tag, etc finder
Plug 'majutsushi/tagbar' " Display ctags in a window, ordered by scope. Plug 'majutsushi/tagbar' " Display ctags in a window, ordered by scope.
Plug 'tommcdo/vim-lion' " For text alignment, use gl= and gL= Plug 'tommcdo/vim-lion' " For text alignment, use gl= and gL=
Plug 'tpope/tpope-vim-abolish' " Easily search for, substitute, and abbreviate multiple variants of a word. Add them to `vim/after/plugin/abolish.vim` Plug 'tpope/tpope-vim-abolish' " Easily search for, substitute, and abbreviate multiple variants of a word. Add them to `vim/after/plugin/abolish.vim`
Plug 'vim-scripts/AnsiEsc.vim' " Ansi escape sequences concealed, but highlighted as specified.
Plug 'sir-pinecone/errormarker.vim' " Build error highlighting (requires skywind3000/asyncrun.vim). Plug 'sir-pinecone/errormarker.vim' " Build error highlighting (requires skywind3000/asyncrun.vim).
Plug 'skywind3000/asyncrun.vim' " Async commands. Plug 'skywind3000/asyncrun.vim' " Async commands.
Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. search and replace). Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. search and replace).
Plug 'editorconfig/editorconfig-vim' " Adds support for .editorconfig files. Plug 'editorconfig/editorconfig-vim' " Adds support for .editorconfig files.
" @flagged for removal
Plug 'sir-pinecone/AnsiEsc.vim' " Ansi escape sequences concealed, but highlighted as specified.
if IsWindows() if IsWindows()
Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so). Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so).
endif endif
@@ -345,6 +374,8 @@ set complete-=i " Don't scan all included files since it's rea
set termguicolors set termguicolors
syntax on " Enable highlighting for syntax syntax on " Enable highlighting for syntax
let g:netrw_dirhistmax = 0 " Disable netrw
set wildmenu set wildmenu
set wildmode=longest,list,full set wildmode=longest,list,full
set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/* set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/*
@@ -353,9 +384,10 @@ if executable('rg')
set grepprg=rg\ --vimgrep\ --hidden " Requires ripgrep to be installed. set grepprg=rg\ --vimgrep\ --hidden " Requires ripgrep to be installed.
endif endif
set list listchars=tab:»·,trail" Show trailing whitespace. " Show trailing tabs and whitespace.
set listchars=tab:»\ ,trail,extends:>,precedes:<,nbsp:+
set timeoutlen=300 ttimeoutlen=0 " Adding this since the esc remap on the 'i' key had a long delay when pressed. set timeoutlen=250 ttimeoutlen=0 " Don't set it too low otherwise you won't be able to type use multi-key sequences.
" @fixme might be broken if lowered to 100 from original value of 4000. Will " @fixme might be broken if lowered to 100 from original value of 4000. Will
" first try 500 and tweak from there. " first try 500 and tweak from there.
@@ -446,7 +478,7 @@ augroup campoCmds
autocmd BufWritePost ~/.vimrc_templates.private silent! source $MYVIMRC autocmd BufWritePost ~/.vimrc_templates.private silent! source $MYVIMRC
" Remove trailing whitespace when saving any file. " Remove trailing whitespace when saving any file.
function! StripTrailingWhitespaces() fu! StripTrailingWhitespaces()
if g:campo_strip_trailing_whitespace == 1 if g:campo_strip_trailing_whitespace == 1
if len(g:campo_directories_to_ignore_when_stripping_trailing_whitespace) if len(g:campo_directories_to_ignore_when_stripping_trailing_whitespace)
for path in g:campo_directories_to_ignore_when_stripping_trailing_whitespace for path in g:campo_directories_to_ignore_when_stripping_trailing_whitespace
@@ -504,6 +536,26 @@ augroup END
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
" Note: if there are two+ mappings that start with the same sequence then vim
" will introduce a delay before the mapping is handled in order to wait for
" the entire sequence to be typed. e.g. <leader>s and <leader>sg will
" introduce a timeout delay, which will be noticed when you're trying to use
" <leader>s. If you type <leader>sg then it'll be handled immediately, unless
" there is a third mapping with that initial sequence, e.g. <leader>sgn.
"
" You can adjust the timeout duration by modidying the timeoutlen option.
"
" You can see when a keysequence is mapped to by entering :map <sequence>
" e.g. :map ,s
" This is helpful when you are experiencing a timeout but you only have one
" mapping defined in your vimrc. It's likely that a plugin added a similar
" mapping sequence.
"
" The difference between map and noremap is that the former does recursive
" expansion and the latter doesn't. The expansion means that if the mapped key
" sequence contains any mappings then those mappings will be expanded as well.
" This can lead to issues and confusion, so it's best to use noremap unless
" you really have a reason not to.
"################################################################################## "##################################################################################
" MISC " MISC
@@ -512,13 +564,16 @@ augroup END
" Lowercase the e (have a habit of making it uppercase). " Lowercase the e (have a habit of making it uppercase).
:ca E e :ca E e
" Mapping ESC in insert mode and command mode to double i. " Bail out of insert mode by double-pressing 'j'.
imap jj <Esc> " Disabling because it's annoying and I now have a keyboard that I can use
" through the Steam Link that lets me map caps to ctrl, so I no longer need
" this.
" imap jj <Esc>
" Suspend vim process and return to the shell. Can return to vim with `fg`. " Suspend vim process and return to the shell. Can return to vim with `fg`.
nnoremap <leader>z <c-z> nnoremap <leader>z <c-z>
" edit a file " Edit a file
nnoremap <leader>e :e nnoremap <leader>e :e
" Open the vimrc file for editing / reload vimrc file. " Open the vimrc file for editing / reload vimrc file.
@@ -562,8 +617,22 @@ noremap <c-h> <c-w><Left>
noremap <leader>m :vsplit<cr> noremap <leader>m :vsplit<cr>
noremap <leader>mm :split<cr> noremap <leader>mm :split<cr>
" Forward delete and replace a word. " Faster way to activate the 'a' register. This is useful for putting different
noremap <leader>d ciw " lines of text into the 'a' register and then pasting it as a group.
" You need to first use `<leader>a` and then subsequent use is <leader>A.
" The paste command will use this content until you do something with a
" different register. You can later paste the 'a' contents using `<leader>a p`
" This overwrites the contents of a.
noremap <leader>a "a
" This appends to a.
noremap <leader>aa "A
" Backward replace word including cursor character.
noremap <leader>d cvb
" Forward replace word.
noremap <leader>e cw
" Allow fast pasting by accessing the system clipboard register. " Allow fast pasting by accessing the system clipboard register.
noremap <leader>p "+p noremap <leader>p "+p
@@ -571,7 +640,7 @@ noremap <leader>p "+p
noremap <leader>pp :set paste! paste?<cr> noremap <leader>pp :set paste! paste?<cr>
" Toggle line numbers. " Toggle line numbers.
noremap <leader>o :set number! number?<cr> nnoremap <leader>o :set number! number?<cr>
" Show spell checking. " Show spell checking.
" You can add new entries to the dict by moving the cursor over the word and pressing `zg`. " You can add new entries to the dict by moving the cursor over the word and pressing `zg`.
@@ -605,7 +674,7 @@ nnoremap <c-g> :%s///g<left><left>
" order to only call it once for a group of saves I've had to remap the " order to only call it once for a group of saves I've had to remap the
" various save commands to a function call. " various save commands to a function call.
function! CreateCtags() fu! CreateCtags()
" Only allow one instance of ctags to run in this directory at any given time. " Only allow one instance of ctags to run in this directory at any given time.
let l:lock_file = "ctags.lock" let l:lock_file = "ctags.lock"
if filereadable(l:lock_file) || filereadable("newtags") if filereadable(l:lock_file) || filereadable("newtags")
@@ -659,54 +728,64 @@ endfun
" These write functions below will not be reloaded because they initiate the " These write functions below will not be reloaded because they initiate the
" save. So if you make changes to them then you need to manually reload this " save. So if you make changes to them then you need to manually reload this
" file using <leader>rv or whatever. :ReloadVimrcError " file using <leader>rv or whatever. :ReloadVimrcError
function! WriteCurrentFileAndCreateCtags() fu! WriteCurrentFileAndCreateCtags()
write! write!
call CreateCtags() call CreateCtags()
endfunction endfu
function! WriteCurrentFileAndCreateCtagsThenQuit() fu! WriteCurrentFileAndCreateCtagsThenQuit()
write! write!
call CreateCtags() call CreateCtags()
quit quit
endfunction endfu
" @fixme Sometimes a :wa that saves multiple files causes vim to hang and use a lot of CPU. " @fixme Sometimes a :wa that saves multiple files causes vim to hang and use a lot of CPU.
function! WriteAllModifiedFilesAndCreateCtags() fu! WriteAllModifiedFilesAndCreateCtags()
wall! wall!
call CreateCtags() call CreateCtags()
endfunction endfu
cnoreabbrev w :call WriteCurrentFileAndCreateCtags() " Create a command abbreviation that only applies when it's at the beginning
cnoreabbrev W :call WriteCurrentFileAndCreateCtags() " of a ex command. If you were to do a normal cnoreabbrev or cabbrev then the
cnoreabbrev wa :call WriteAllModifiedFilesAndCreateCtags() " subsitution can happen anywhere in the command line. It was mostly affecting
cnoreabbrev Wa :call WriteAllModifiedFilesAndCreateCtags() " my text search; I'd type '/w' and it would be replaced with the call to save
cnoreabbrev WA :call WriteAllModifiedFilesAndCreateCtags() " and create ctags.
cnoreabbrev wq :call WriteCurrentFileAndCreateCtagsThenQuit() fu! Cabbrev(key, value)
cnoreabbrev Wq :call WriteCurrentFileAndCreateCtagsThenQuit() exe printf('cabbrev <expr> %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s',
cnoreabbrev WQ :call WriteCurrentFileAndCreateCtagsThenQuit() \ a:key, len(a:key)+1, string(a:value), string(a:key))
endfu
call Cabbrev('w', 'call WriteCurrentFileAndCreateCtags()')
call Cabbrev('W', 'call WriteCurrentFileAndCreateCtags()')
call Cabbrev('wa', 'call WriteAllModifiedFilesAndCreateCtags()')
call Cabbrev('Wa', 'call WriteAllModifiedFilesAndCreateCtags()')
call Cabbrev('WA', 'call WriteAllModifiedFilesAndCreateCtags()')
call Cabbrev('wq', 'call WriteCurrentFileAndCreateCtagsThenQuit()')
call Cabbrev('Wq', 'call WriteCurrentFileAndCreateCtagsThenQuit()')
call Cabbrev('WQ', 'call WriteCurrentFileAndCreateCtagsThenQuit()')
nnoremap <leader>w :call WriteCurrentFileAndCreateCtags()<cr> nnoremap <leader>w :call WriteCurrentFileAndCreateCtags()<cr>
nnoremap <leader>x :call WriteCurrentFileAndCreateCtagsThenQuit()<cr> nnoremap <leader>x :call WriteCurrentFileAndCreateCtagsThenQuit()<cr>
nnoremap <leader>q :q<cr> nnoremap <leader>q :q<cr>
cnoreabbrev Q q call Cabbrev('Q', 'q')
cnoreabbrev Qa qa call Cabbrev('Qa', 'qa')
command! Qa qall command! Qa qall
" Disable Ex mode. " Disable Ex mode.
noremap Q <Nop> noremap Q <Nop>
"################################################################################## "##################################################################################
" MULTIPURPOSE TAB KEY " MULTIPURPOSE TAB KEY
"################################################################################## "##################################################################################
function! InsertTabWrapper()
fu! InsertTabWrapper()
let l:col = col('.') - 1 let l:col = col('.') - 1
if !l:col || getline('.')[l:col - 1] !~ '\k' if !l:col || getline('.')[l:col - 1] !~ '\k'
return "\<tab>" return "\<tab>"
else else
return "\<c-p>" return "\<c-p>"
endif endif
endfunction endfu
inoremap <tab> <c-r>=InsertTabWrapper()<cr> inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n> inoremap <s-tab> <c-n>
@@ -780,28 +859,6 @@ let g:syntastic_check_on_wq = 0
let g:rg_highlight = 1 let g:rg_highlight = 1
let g:rg_window_height = g:quickfix_pane_height let g:rg_window_height = g:quickfix_pane_height
"##################################################################################
" C-TAGS
"##################################################################################
" Set extra paths to use when searching for ctags files. By default the current
" directory is always checked. You can use this to combine tag lookups from
" different projects, e.g. set it to the Jai directory and you can look up
" current project tags and Jai module tags (of course this isn't needed if you
" have Jai module tags in your local file).
"
" This destructively overwrites the tags option value.
"
" Call this from a .vimrc.private or .lvimrc file, e.g.
" call g:SetExtraCtagsPaths([g:campo_jai_path.'/tags'])
"
function! g:SetExtraCtagsPaths(paths_array)
let l:list = './tags,tags' " This is the default tags list set by vim.
for path in a:paths_array
let l:list .= ',' . path
endfor
let &tags=l:list
endfunction
"################################################################################## "##################################################################################
" CTRL-P " CTRL-P
"################################################################################## "##################################################################################
@@ -830,12 +887,12 @@ endfunction
" window and cmdline events but wasn't able to find anything that fired AFTER " window and cmdline events but wasn't able to find anything that fired AFTER
" the tag command. So we're instead just setting the tags list once for the " the tag command. So we're instead just setting the tags list once for the
" session and not bothering with changing it on the fly. See g:SetExtraCtagsPaths " session and not bothering with changing it on the fly. See g:SetExtraCtagsPaths
function! CtrlP_Search(search_path) fu! CtrlP_Search(search_path)
" If a:search_path is empty then ctrlp will use g:ctrlp_working_path_mode to determine the cwd to search in. " If a:search_path is empty then ctrlp will use g:ctrlp_working_path_mode to determine the cwd to search in.
execute 'CtrlP ' . a:search_path execute 'CtrlP ' . a:search_path
endfunction endfu
function! CtrlP_JaiSearch(jai_rel_search_path) fu! CtrlP_JaiSearch(jai_rel_search_path)
if g:campo_jai_path == '' if g:campo_jai_path == ''
call PrintError("g:campo_jai_path isn't set!") call PrintError("g:campo_jai_path isn't set!")
return return
@@ -849,7 +906,7 @@ function! CtrlP_JaiSearch(jai_rel_search_path)
return return
endif endif
call CtrlP_Search(l:path) call CtrlP_Search(l:path)
endfunction endfu
" CtrlP File Searching " CtrlP File Searching
noremap <leader>g :call CtrlP_Search('')<cr> " Search in current directory noremap <leader>g :call CtrlP_Search('')<cr> " Search in current directory
@@ -877,14 +934,6 @@ noremap <leader>gb :Git blame -w<cr>
command! -bar -bang -nargs=* Blame :Git blame<bang> -wCM <args> command! -bar -bang -nargs=* Blame :Git blame<bang> -wCM <args>
command! -bar -bang -nargs=* Gblame :Git blame<bang> -wCM <args> command! -bar -bang -nargs=* Gblame :Git blame<bang> -wCM <args>
"##################################################################################
" GIST VIM
"##################################################################################
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_show_privates = 1
let g:gist_post_private = 1
"################################################################################## "##################################################################################
" VIM-CLOJURE-STATIC " VIM-CLOJURE-STATIC
"################################################################################## "##################################################################################
@@ -907,7 +956,7 @@ let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gr
let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray'] let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray']
let s:rainbow_theme = g:campo_light_dark_mode let s:rainbow_theme = g:campo_light_dark_mode
function! UpdateRainbowConf() fu! UpdateRainbowConf()
let g:rainbow_conf = { let g:rainbow_conf = {
\ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow) \ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow)
\} \}
@@ -915,11 +964,11 @@ function! UpdateRainbowConf()
"\ '*': 0, " Disable all "\ '*': 0, " Disable all
"\ 'c++': {} " Only enable c++ "\ 'c++': {} " Only enable c++
"\ } "\ }
endfunction endfu
call UpdateRainbowConf() call UpdateRainbowConf()
function! ReloadRainbow() fu! ReloadRainbow()
if g:campo_theme_use_rainbow_parens if g:campo_theme_use_rainbow_parens
if exists(':RainbowToggle') if exists(':RainbowToggle')
call UpdateRainbowConf() call UpdateRainbowConf()
@@ -932,7 +981,7 @@ function! ReloadRainbow()
call rainbow#clear() call rainbow#clear()
endif endif
endif endif
endfunction endfu
"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -954,15 +1003,15 @@ noremap <leader>l :call ToggleLightDarkTheme()<cr>
let s:current_light_dark_mode = g:campo_light_dark_mode let s:current_light_dark_mode = g:campo_light_dark_mode
function! ToggleLightDarkTheme() fu! ToggleLightDarkTheme()
if s:current_light_dark_mode == 'light' if s:current_light_dark_mode == 'light'
call ChangeLightDarkMode('dark', 0) call ChangeLightDarkMode('dark', 0)
else else
call ChangeLightDarkMode('light', 0) call ChangeLightDarkMode('light', 0)
endif endif
endfunction endfu
function! ChangeLightDarkMode(mode, onlySetTheme) fu! ChangeLightDarkMode(mode, onlySetTheme)
if a:mode == 'light' if a:mode == 'light'
let s:rainbow_theme = 'light' let s:rainbow_theme = 'light'
let s:theme = g:campo_light_theme let s:theme = g:campo_light_theme
@@ -983,7 +1032,7 @@ function! ChangeLightDarkMode(mode, onlySetTheme)
if !a:onlySetTheme if !a:onlySetTheme
exec 'AirlineTheme' a:mode exec 'AirlineTheme' a:mode
endif endif
endfunction endfu
" Set the intial light/dark mode. " Set the intial light/dark mode.
if g:campo_light_dark_mode =~ 'light' if g:campo_light_dark_mode =~ 'light'
@@ -993,14 +1042,14 @@ else
endif endif
" Open the current color scheme for editing. " Open the current color scheme for editing.
function! EditColorScheme() fu! EditColorScheme()
let l:path = g:vim_dir . '/colors/' . s:theme . '.vim' let l:path = g:vim_dir . '/colors/' . s:theme . '.vim'
if filereadable(l:path) if filereadable(l:path)
execute 'vsplit ' . l:path execute 'vsplit ' . l:path
else else
call PrintError("Failed to open " . l:path . " for editing.") call PrintError("Failed to open " . l:path . " for editing.")
endif endif
endfunction endfu
command -nargs=0 EditColorScheme call EditColorScheme() command -nargs=0 EditColorScheme call EditColorScheme()
@@ -1084,10 +1133,10 @@ let errormarker_warninggroup = "BuildWarn"
let errormarker_infogroup = "BuildInfo" let errormarker_infogroup = "BuildInfo"
" I don't know how to map to a plugin command, so I'm wrapping it with a function...ugh. " I don't know how to map to a plugin command, so I'm wrapping it with a function...ugh.
function! ShowErrorAtCursor() fu! ShowErrorAtCursor()
" This is defined in errormarker.vim " This is defined in errormarker.vim
ErrorAtCursor ErrorAtCursor
endfunction endfu
nnoremap <leader>ce :call ShowErrorAtCursor()<cr> nnoremap <leader>ce :call ShowErrorAtCursor()<cr>
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
@@ -1098,7 +1147,7 @@ nnoremap <leader>ce :call ShowErrorAtCursor()<cr>
" This will print the valid entries. You'll know parsing is correct when the " This will print the valid entries. You'll know parsing is correct when the
" entries have a type, line num, error message, etc. " entries have a type, line num, error message, etc.
function! ShowErrorEntries() fu! ShowErrorEntries()
" Prints out valid quickfix errors. " Prints out valid quickfix errors.
redraw! redraw!
for l:d in getqflist() for l:d in getqflist()
@@ -1106,7 +1155,7 @@ function! ShowErrorEntries()
echomsg l:d echomsg l:d
endif endif
endfor endfor
endfunction endfu
command -nargs=0 ShowErrorEntries call ShowErrorEntries() command -nargs=0 ShowErrorEntries call ShowErrorEntries()
" Jai " Jai
@@ -1140,25 +1189,25 @@ set errorformat+=\\\ %#%f(%l\\\,%c-%*[0-9]):\ %#%t%[A-z]%#\ %m
" BUILD FUNCTIONS " BUILD FUNCTIONS
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
function! HideBuildResultsAndClearErrors() fu! HideBuildResultsAndClearErrors()
RemoveErrorMarkers RemoveErrorMarkers
call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0) call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0)
endfunction endfu
function! HideAsyncResults() fu! HideAsyncResults()
call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0) call asyncrun#quickfix_toggle(g:quickfix_pane_height, 0)
endfunction endfu
function! ToggleBuildResults() fu! ToggleBuildResults()
call asyncrun#quickfix_toggle(g:quickfix_pane_height) call asyncrun#quickfix_toggle(g:quickfix_pane_height)
endfunction endfu
function! StopRunTask() fu! StopRunTask()
AsyncStop AsyncStop
call HideAsyncResults() call HideAsyncResults()
endfunction endfu
function! Build(optimized=0, silent=0) fu! Build(optimized=0, silent=0)
let l:async_cmd = "AsyncRun! " let l:async_cmd = "AsyncRun! "
if a:silent if a:silent
let l:async_cmd .= "-post=call\\ HideAsyncResults() " let l:async_cmd .= "-post=call\\ HideAsyncResults() "
@@ -1168,7 +1217,8 @@ function! Build(optimized=0, silent=0)
let l:has_jai_build_file = 0 let l:has_jai_build_file = 0
let l:ext = tolower(expand('%:e')) let l:ext = tolower(expand('%:e'))
let l:current_dir = expand('%:p:h') let l:current_dir = expand('%:p:h')
let l:one_dir_back = expand('%:p:h:h')
let l:cmd = "" let l:cmd = ""
@@ -1177,15 +1227,16 @@ function! Build(optimized=0, silent=0)
" Check for a build file in the current directory or one directory back " Check for a build file in the current directory or one directory back
" (e.g. we're in modules/ or src/, code/, etc) " (e.g. we're in modules/ or src/, code/, etc)
if filereadable(l:current_dir . "/build.jai") || filereadable(l:current_dir . "/../build.jai") if filereadable(l:current_dir . "/build.jai") || filereadable(l:one_dir_back . "/build.jai")
let l:has_jai_build_file = 1 let l:has_jai_build_file = 1
let l:cmd = "jai " . l:current_dir . "/"
if filereadable(l:current_dir . "/build.jai") == 1 if filereadable(l:current_dir . "/build.jai") == 1
let l:cmd .= "build.jai" let l:cmd = "jai ". l:current_dir . "/build.jai"
else else
let l:cmd .= "../build.jai" " It's one directory back. We don't want to include '../' in
" the cmd because then our reported paths in the program get
" botched, e.g. path shown in an assert error.
let l:cmd = "jai " . l:one_dir_back . "/build.jai"
endif endif
else else
let l:cmd = "jai % " let l:cmd = "jai % "
@@ -1205,12 +1256,12 @@ function! Build(optimized=0, silent=0)
if a:optimized == 1 if a:optimized == 1
echo "Compiling release build.jai" echo "Compiling release build.jai"
" @note We pass 'release' as a user metaprogram arg for the " @note We pass 'release' as a user metaprogram arg for the
" build file to parse. -release is a compiler arg and we don't " build file to parse in case it cares about that. -release is
" want to use that. Ideally the build script would ignore that " a compiler arg that we also include because some build
" completely. Also we don't bother adding an import directory " scripts won't be looking at the user metaprogram args.
" for local modules because the build file should manage that " We also don't bother adding an import directory for local modules
" sort of thing for us. " because the build file should manage that sort of thing for us.
let l:cmd .= " - release" let l:cmd .= " -release - release"
let l:set_metaprogram_args = 1 let l:set_metaprogram_args = 1
else else
echo "Compiling debug build.jai" echo "Compiling debug build.jai"
@@ -1229,7 +1280,7 @@ function! Build(optimized=0, silent=0)
endif endif
endif endif
if g:campo_jai_compiler_args != "" if g:campo_jai_metaprogram_args != ""
if l:set_metaprogram_args == 1 if l:set_metaprogram_args == 1
let l:cmd .= ' '.g:campo_jai_metaprogram_args let l:cmd .= ' '.g:campo_jai_metaprogram_args
else else
@@ -1243,35 +1294,69 @@ function! Build(optimized=0, silent=0)
" be generated so we're handling the save ourselves. " be generated so we're handling the save ourselves.
call WriteAllModifiedFilesAndCreateCtags() call WriteAllModifiedFilesAndCreateCtags()
exec l:async_cmd . l:cmd exec l:async_cmd . l:cmd
endfunction endfu
function! RunProgram() fu! RunProgram()
if filereadable("run") let l:ran = 0
exec "AsyncRun! -post=call\\ StopRunTask() ./run %" let l:ext = tolower(expand('%:e'))
else let l:path_to_use = ""
let l:ext = tolower(expand('%:e'))
if l:ext == "jai" if l:ext == "jai"
if filereadable(expand('%:p:r') . '.exe') " Maybe the current file has an exe, i.e. wasn't compiled with a build script.
exec "AsyncRun! " . expand('%:p:r') . ".exe" if filereadable(expand('%:p:r') . '.exe')
let l:ran = 1
exec "AsyncRun! " . expand('%:p:r') . ".exe"
elseif tolower(expand('%:h:t')) == "modules" || tolower(expand('%:h:h:t')) == "modules"
" This is likely a jai module inside a project. We will want to do the exe/run script checks in the parent project folder.
" The :h:h tests for a module inside a folder, e.g. modules/Basic/module.jai
echo "module"
if tolower(expand('%:h:t')) == "modules"
let l:path_to_use = "/.."
else else
if tolower(expand('%:h')) == "modules" let l:path_to_use = "/../.."
" This is likely a jai module inside a project. Check for an " exe one directory back. endif
let l:files = systemlist('ls ' . expand('%:p:h') . '/../*.exe 2>/dev/null') endif
else elseif l:ext == "py"
let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null') let l:ran = 1
endif exec "AsyncRun! python %"
endif
if l:ran == 0
" First check the current file's directory (and one directory back)
" for a run script, falling back to the current working directory (and
" one directory back) of the editor.
if filereadable(expand('%:h') . '/run')
echo "file here"
exec "AsyncRun! " . expand('%:h') . "/run"
elseif filereadable(expand('%:h') . '/../run')
" Handles editing a file in a code/ or src/ and there's a run script one directory back.
echo "file one back"
exec "AsyncRun! " . expand('%:h') . "/../run"
elseif filereadable("run")
echo "cwd here"
exec "AsyncRun! ./run"
elseif filereadable("../run")
" Handles editing a file in a code/ or src/ and there's a run script one directory back.
echo "cwd one back"
exec "AsyncRun! ../run"
else
" Final attempt is to run any exe that's found nearby.
" We start with an exe relative to the open file's path.
let l:files = systemlist('ls '.expand('%:h').''.l:path_to_use.'/*.exe 2>/dev/null')
if len(l:files) > 0
exec "AsyncRun! " . l:files[0]
else
" Last attempt is any exe in the current working directory.
let l:files = systemlist('ls *.exe 2>/dev/null')
if len(l:files) > 0 if len(l:files) > 0
exec "AsyncRun! " . l:files[0] exec "AsyncRun! " . l:files[0]
else else
call PrintError("No exe found. Compile first?") call PrintError("No exe or run script found!")
endif endif
endif endif
elseif l:ext == "py"
exec "AsyncRun! python %"
endif endif
endif endif
endfunction endfu
" Show results window the moment the async job starts " Show results window the moment the async job starts
augroup asyncPluginCmds augroup asyncPluginCmds
@@ -1313,7 +1398,7 @@ nnoremap <C-p> :cp<CR>
"################################################################################## "##################################################################################
" Search using ripgrep (first install with Rust: cargo install ripgrep). " Search using ripgrep (first install with Rust: cargo install ripgrep).
function! Search(path, search_args, case_insensitive=0) fu! Search(path, search_args, case_insensitive=0)
let l:helper = "Search '" . a:path . "' (" . (len(a:search_args) > 0 ? a:search_args . " | " : '') . (a:case_insensitive ? "INSENSITIVE" : "SENSITIVE") . "): " let l:helper = "Search '" . a:path . "' (" . (len(a:search_args) > 0 ? a:search_args . " | " : '') . (a:case_insensitive ? "INSENSITIVE" : "SENSITIVE") . "): "
let l:term = input(l:helper) let l:term = input(l:helper)
if empty(l:term) if empty(l:term)
@@ -1334,40 +1419,80 @@ function! Search(path, search_args, case_insensitive=0)
let l:format = 'Rg ' . l:rg_args . ' ' . a:path . ' -e %s' let l:format = 'Rg ' . l:rg_args . ' ' . a:path . ' -e %s'
let l:cmd = printf(l:format, shellescape(l:escaped_term)) let l:cmd = printf(l:format, shellescape(l:escaped_term))
exec l:cmd exec l:cmd
endfunction endfu
fu! SearchExt(path, search_args, case_insensitive=0)
call inputsave()
let l:ext = input('Enter extension to search on (leave blank for files with no ext): ')
call inputrestore()
redraw!
if empty(l:ext)
let l:ext = "!*.*"
else
let l:ext = "*.".l:ext
endif
let l:args = a:search_args." -g \"".l:ext."\""
call Search(a:path, l:args, a:case_insensitive)
endfu
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" SEARCH IN CURRENT DIRECTORY " SEARCH IN CURRENT WORKING DIRECTORY
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" Case insensitive: " Case insensitive:
noremap <leader>s :call Search('.', g:campo_custom_search_args, 1)<cr> nnoremap <leader>s :call Search( '.', g:campo_custom_search_args, 1)<cr>
nnoremap <leader>sd :call SearchExt('.', g:campo_custom_search_args, 1)<cr>
" Case sensitive: " Case sensitive:
noremap <leader>ss :call Search('.', g:campo_custom_search_args)<cr> nnoremap <leader>ss :call Search( '.', g:campo_custom_search_args, 0)<cr>
nnoremap <leader>ssd :call SearchExt('.', g:campo_custom_search_args, 0)<cr>
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" SEARCH IN DIRECTORY CONTAINING THE ACTIVE FILE " SEARCH IN DIRECTORY CONTAINING THE ACTIVE FILE
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" Case insensitive: " Case insensitive:
noremap <leader>sf :call Search(expand('%:p:h'), g:campo_custom_search_args, 1)<cr> nnoremap <leader>sf :call Search( expand('%:p:h'), g:campo_custom_search_args, 1)<cr>
nnoremap <leader>sdf :call SearchExt(expand('%:p:h'), g:campo_custom_search_args, 1)<cr>
" Case sensitive: " Case sensitive:
noremap <leader>ssf :call Search(expand('%:p:h'), g:campo_custom_search_args)<cr> nnoremap <leader>ssf :call Search( expand('%:p:h'), g:campo_custom_search_args, 0)<cr>
nnoremap <leader>ssdf :call SearchExt(expand('%:p:h'), g:campo_custom_search_args, 0)<cr>
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" SEARCH IN JAI FOLDERS " SEARCH IN JAI FOLDERS
"///////////////////////////////////////////////// "/////////////////////////////////////////////////
" Case insensitive: " Case insensitive:
noremap <leader>sg :call Search(g:campo_jai_path, g:campo_custom_search_args, 1)<cr> "
noremap <leader>sm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args, 1)<cr> " ROOT
noremap <leader>sh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args, 1)<cr> nnoremap <leader>sg :call Search( g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
noremap <leader>se :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args, 1)<cr> nnoremap <leader>sdg :call SearchExt(g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
" MODULES
nnoremap <leader>sm :call Search( g:campo_jai_path.'/modules', g:campo_custom_search_args, 1)<cr>
nnoremap <leader>sdm :call SearchExt(g:campo_jai_path.'/modules', g:campo_custom_search_args, 1)<cr>
" HOW TO
nnoremap <leader>sh :call Search( g:campo_jai_path.'/how_to', g:campo_custom_search_args, 1)<cr>
nnoremap <leader>sdh :call SearchExt(g:campo_jai_path.'/how_to', g:campo_custom_search_args, 1)<cr>
" EXAMPLES
nnoremap <leader>se :call Search( g:campo_jai_path.'/examples', g:campo_custom_search_args, 1)<cr>
nnoremap <leader>sde :call SearchExt(g:campo_jai_path.'/examples', g:campo_custom_search_args, 1)<cr>
" Case sensitive: " Case sensitive:
noremap <leader>ssg :call Search(g:campo_jai_path, g:campo_custom_search_args)<cr> "
noremap <leader>ssm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args)<cr> " ROOT
noremap <leader>ssh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args)<cr> nnoremap <leader>ssg :call Search( g:campo_jai_path, g:campo_custom_search_args, 0)<cr>
noremap <leader>sse :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args)<cr> nnoremap <leader>ssdg :call SearchExt(g:campo_jai_path, g:campo_custom_search_args, 0)<cr>
" MODULES
nnoremap <leader>ssm :call Search( g:campo_jai_path.'/modules', g:campo_custom_search_args, 0)<cr>
nnoremap <leader>ssdm :call SearchExt(g:campo_jai_path.'/modules', g:campo_custom_search_args, 0)<cr>
" HOW TO
nnoremap <leader>ssh :call Search( g:campo_jai_path.'/how_to', g:campo_custom_search_args, 0)<cr>
nnoremap <leader>ssdh :call SearchExt(g:campo_jai_path.'/how_to', g:campo_custom_search_args, 0)<cr>
" EXAMPLES
nnoremap <leader>sse :call Search( g:campo_jai_path.'/examples', g:campo_custom_search_args, 0)<cr>
nnoremap <leader>ssde :call SearchExt(g:campo_jai_path.'/examples', g:campo_custom_search_args, 0)<cr>
" Navigation for the vim-ripgrep search results. " Navigation for the vim-ripgrep search results.
" Hit o on a result line to open the file at that line. " Hit o on a result line to open the file at that line.
@@ -1387,7 +1512,7 @@ nnoremap <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "p")
" Replace text in a git repo's committed files. " Replace text in a git repo's committed files.
" The range identifier allows us to run this once when multiple lines are selected in a file. " The range identifier allows us to run this once when multiple lines are selected in a file.
function! GlobalReplaceIt(confirm_replacement) range fu! GlobalReplaceIt(confirm_replacement) range
if exists(':Ggrep') if exists(':Ggrep')
call inputsave() call inputsave()
if a:confirm_replacement if a:confirm_replacement
@@ -1440,7 +1565,7 @@ function! GlobalReplaceIt(confirm_replacement) range
else else
call PrintError("Unable to search since you're not in a git repo!") call PrintError("Unable to search since you're not in a git repo!")
endif endif
endfunction endfu
noremap <leader>r :call GlobalReplaceIt(0)<cr> noremap <leader>r :call GlobalReplaceIt(0)<cr>
noremap <leader>rr :call GlobalReplaceIt(1)<cr> noremap <leader>rr :call GlobalReplaceIt(1)<cr>
@@ -1449,7 +1574,7 @@ noremap <leader>rr :call GlobalReplaceIt(1)<cr>
" RENAME CURRENT FILE " RENAME CURRENT FILE
"################################################################################## "##################################################################################
function! RenameFile() fu! RenameFile()
let l:old_name = expand('%') let l:old_name = expand('%')
let l:new_name = input('New file name: ', expand('%'), 'file') let l:new_name = input('New file name: ', expand('%'), 'file')
if l:new_name != '' && l:new_name != l:old_name if l:new_name != '' && l:new_name != l:old_name
@@ -1460,7 +1585,7 @@ function! RenameFile()
redraw! redraw!
endif endif
endif endif
endfunction endfu
noremap <leader>n :call RenameFile()<cr> noremap <leader>n :call RenameFile()<cr>
@@ -1468,19 +1593,19 @@ noremap <leader>n :call RenameFile()<cr>
" CENTER THE BUFFER " CENTER THE BUFFER
"################################################################################## "##################################################################################
function! CenterPane() fu! CenterPane()
" Centers the current pane as the middle 2 of 4 imaginary columns should " Centers the current pane as the middle 2 of 4 imaginary columns should
" be called in a window with a single pane. " be called in a window with a single pane.
" Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim " Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim
lefta vnew lefta vnew
wincmd w wincmd w
exec 'vertical resize' string(&columns * 0.65) exec 'vertical resize' string(&columns * 0.65)
endfunction endfu
function! RemoveCenterPane() fu! RemoveCenterPane()
wincmd w wincmd w
close close
endfunction endfu
nnoremap <leader>cc :call CenterPane()<cr> nnoremap <leader>cc :call CenterPane()<cr>
nnoremap <leader>cd :call RemoveCenterPane()<cr> nnoremap <leader>cd :call RemoveCenterPane()<cr>
@@ -1493,7 +1618,7 @@ nnoremap <leader>cd :call RemoveCenterPane()<cr>
" Applies a clean view of the current buffer by turning off line " Applies a clean view of the current buffer by turning off line
" numbers, trailing spaces, tabs and git diff markers in the gutter. " numbers, trailing spaces, tabs and git diff markers in the gutter.
function! ToggleSimpleView() fu! ToggleSimpleView()
" I wasn't able to get this to apply to every copy of the same buffer, " I wasn't able to get this to apply to every copy of the same buffer,
" e.g. you have a split view showing the same file; only the active one " e.g. you have a split view showing the same file; only the active one
" will be affected, but they will share the same state! I tried many " will be affected, but they will share the same state! I tried many
@@ -1519,7 +1644,7 @@ function! ToggleSimpleView()
setlocal list setlocal list
exec 'GitGutterBufferEnable' exec 'GitGutterBufferEnable'
endif endif
endfunction endfu
nnoremap <leader>c :call ToggleSimpleView()<cr> nnoremap <leader>c :call ToggleSimpleView()<cr>

View File

View File

View File

@@ -1,11 +0,0 @@
# dotfiles
Various dotfiles and misc configs. Some of it is customized around my system setup
(like aliases pointing to paths) but you should be able to easily remove that stuff.
## Installing
There is an `install` script that facilitates the setup, however it's been a while since I did a
full system setup and this script may not be fully complete. An alternative method is to manually
symlink files in the root directory. OS specific configs are in their respective folders.

View File

@@ -1,16 +0,0 @@
#!/usr/bin/env bash
# Copies vim data from the home directory to the dotfiles repo.
set -e
src="$HOME/.vim"
dest="$HOME/.dotfiles/vim/"
if [ -d $src ]; then
[ -d "$src/spell" ] && echo "Syncing user dictionary" && cp -r "$src/spell" $dest
[ -d "$src/colors" ] && echo "Syncing user colors" && cp -r "$src/colors" $dest
[ -d "$src/after" ] && echo "Syncing after directory" && cp -r "$src/after" $dest
[ -d "$src/ftdetect" ] && echo "Syncing ftdetect" && cp -r "$src/ftdetect" $dest
[ -d "$src/autoload" ] && echo "Syncing autoload" && cp -r "$src/autoload" $dest
fi

View File

@@ -1,16 +0,0 @@
#!/usr/bin/env bash
# Copies vim data from the dotfiles repo to the home directory.
set -e
src="$HOME/.dotfiles/vim"
dest="$HOME/.vim/"
if [ -d $src ]; then
[ -d "$src/spell" ] && echo "Syncing user dictionary" && cp -r "$src/spell" $dest
[ -d "$src/colors" ] && echo "Syncing user colors" && cp -r "$src/colors" $dest
[ -d "$src/after" ] && echo "Syncing after directory" && cp -r "$src/after" $dest
[ -d "$src/ftdetect" ] && echo "Syncing ftdetect" && cp -r "$src/ftdetect" $dest
[ -d "$src/autoload" ] && echo "Syncing autoload" && cp -r "$src/autoload" $dest
fi

32
dotfiles/README.md Normal file
View File

@@ -0,0 +1,32 @@
# dotfiles
Various dotfiles and misc configs. Some of it is customized around my system
setup (like aliases pointing to paths) but you should be able to easily remove
that stuff.
This unpacks files one directory back, which is assumed to be your home
directory. The gitignore ignores all files by default. If you want to add a new
file this you need to add the `-f` flag to the git add command. This setup was
inspired by Gary Bernhardt and https://gist.github.com/meleu/053275b6842646b95491bf1af4a6ca0e
## Installing
```bash
# Go to your home directory.
cd ~
# Clone the repo with the "--no-checkout" option (so we can checkout the files in our home directory)
git clone --no-checkout <repo_url>/dotfiles.git
# Go to the created directory and change the worktree to the home direcory.
cd dotfiles
git config core.worktree '../../'
# Checkout the files. This will overwrite existing dotfiles with the same name.
git reset --hard origin/master
```
If you want to install optional OS specific stuff, like various packages, run the `install` script in this folder.
OS specific configs are in their respective folders.

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
input="$1"
output_name="$2"
if [[ $input == "" || $output_name == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <input video> <wav output name>${NORMAL}\n"
exit 1
fi
if [[ ! -f "$input" ]]; then
printf "${RED}${BOLD}Error: failed to extract audio. Video file \"$input\" doesn't exist.\n${NORMAL}"
exit 1
fi
# Add extension if not provided.
output_basename=$(basename -- "$output_name")
output_extension="${output_basename##*.}"
if [[ $output_extension != "wav" ]]; then
output_name="${output_name}.wav"
fi
printf "\n${YELLOW}${BOLD}Extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"
ffmpeg -i "$input" -ar 16000 -ac 1 -c:a pcm_s16le "$output_name"
printf "${GREEN}${BOLD}Done extracting 16-bit WAV from $input | output: $output_name${NORMAL}\n"

View File

@@ -41,7 +41,7 @@ if [[ $bitrate == "" ]]; then
bitrate="64" bitrate="64"
fi fi
printf "\n${YELLOW}${BOLD}Extracting audio from '$filename.$extension' | bitrate: ${bitrate}k | output: $output_name${NORMAL}\n" printf "\n${YELLOW}${BOLD}Extracting audio from $filename.$extension | bitrate: ${bitrate}k | output: $output_name${NORMAL}\n"
if [[ $transcode == "1" ]]; then if [[ $transcode == "1" ]]; then
# Transcode audio # Transcode audio
@@ -51,5 +51,5 @@ else
ffmpeg -i "$filename.$extension" -vn -acodec copy "$output_name" ffmpeg -i "$filename.$extension" -vn -acodec copy "$output_name"
fi fi
printf "\n${GREEN}${BOLD}Done extracting audio from '$filename.$extension' | output name '$output_name'${NORMAL}\n\n" printf "\n${GREEN}${BOLD}Done extracting audio from $filename.$extension | output name '$output_name'${NORMAL}\n\n"

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source "$HOME/.dotfiles/script_helpers/all.sh" source "$HOME/dotfiles/script_helpers/all.sh"
cwd=$PWD cwd=$PWD
source_path="" source_path=""

View File

@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# The base model is pretty good overall. It has good punctuation inserting and catches most words.
# Tiny is fast and often has correct grammar, but it misses a lot of words, especially when the
# source isn't loud or is muffled.
#
# Small and medium models can do better word detection at times, but suffer from a lack of punctuation.
# Medium is particularly bad and often excludes periods and commas.
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
# Will return a symlink path in its expanded form. If the path's root is the
# home directory symbol "~" then it'll be replaced by the full home path.
expand_path() {
local ret="$1"
IFS="/" read -ra parts <<< "$ret"
if [[ "${parts[0]}" == "~" ]]; then
ret="$HOME"
for ((i=1; i < ${#parts[@]}; i++))
do
ret="$ret/${parts[$i]}"
done
fi
ret=$(readlink -m "$ret")
echo $ret
}
input_wav="$1"
output_name_without_ext="$2"
model="$3"
threads=$4
# 4 seems to be the sweet spot for most models, except medium might be faster with 8.
default_thread_count=4
if [[ $input_wav == "" || $output_name_without_ext == "" || $model == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <input.wav> <output name without extension> <model name> <optional: thread count>${NORMAL}\n"
exit 1
fi
if [[ ! -f "$input_wav" ]]; then
printf "${RED}${BOLD}Input file \"$input_wav\" doesn't exist!\n${NORMAL}"
exit 1
fi
if [[ $threads == "" ]]; then
threads=$default_thread_count
fi
output_name="$output_name_without_ext.${model}"
# 1 core 31 threads has very fast pcm_to_mel conversion and then just one core doing most of the work. You get more accurate results this way.
# 2 core 16 is about half the time but it can have errors where the two pieces come together. This only gets more likely as the core count is increased.
# 8 threads, 4 cores is good too for tiny,small and 2 threads, 4 cores for medium.
threads=31 #keep a thread for me
cores=1
printf "\n${YELLOW}${BOLD}Transcribing $input_wav | model: $model | cores: $cores | threads: $threads | output: $output_name ${NORMAL}\n"
whisper_fullname="$(expand_path $(which whisper.exe))"
whisper_path="$(dirname $whisper_fullname)"
models_path="$whisper_path/models"
whisper.exe --processors ${cores} --threads ${threads} -m "$models_path/ggml-${model}.en.bin" -otxt -osrt -f "$input_wav" -of "$output_name" --print-colors --print-progress
error=$?
if [[ error -eq 0 ]]; then
printf "${GREEN}${BOLD}Done transcribing $input_wav | model: $model | cores: $cores | threads: $threads | output: $output_name${NORMAL}\n"
else
printf "${GREEN}${BOLD}Error while transcribing $input_wav | model: $model | cores: $cores | threads: $threads | output: $output_name${NORMAL}\n"
fi

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
input_video="$1"
output_name_without_ext="$2"
shift 2
models=("$@")
if [[ $input_video == "" || $output_name_without_ext == "" || ${#models[@]} -eq 0 ]]; then
printf "${BOLD}${RED}Usage: $0 <input.mp4> <output name without extension> <list of model names to use>${NORMAL}\n"
exit 1
fi
model_csv=$(IFS=_ ; echo "${models[*]}")
wav_name="${output_name_without_ext}_${model_csv}_${RANDOM}"
# Add extension if not provided.
input_basename=$(basename -- "$wav_name")
input_extension="${input_basename##*.}"
if [[ input_extension != "wav" ]]; then
wav_name="${wav_name}.wav"
fi
extract-16bit-wav-from-video "$input_video" "$wav_name"
if [[ $? == 1 ]]; then exit 1; fi
for model in "$@"; do
# Tweak thread count based on model size.
thread_count=4
if [[ $model == "medium" ]]; then
thread_count=8
fi
transcribe-audio "$wav_name" "$output_name_without_ext" "${model}" $thread_count
if [[ $? == 1 ]]; then
printf "${RED}${BOLD}Saving the audio file \"$wav_name\" in case you want to reuse it for debugging.\n${NORMAL}"
exit 1
fi
done
rm "$wav_name"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
transcribe-video "$1" "$2" "base"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
transcribe-video "$1" "$2" "medium"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
transcribe-video "$1" "$2" "small"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
transcribe-video "$1" "$2" "tiny"

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Reencodes the video with a more accurate length.
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
MAGENTA="$(tput setaf 5)"
CYAN="$(tput setaf 6)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
filename=$(basename -- "$1")
output_name="$2"
start_time="$3"
end_time="$4"
if [[ $filename == "" || $output_name == "" || $start_time == "" || $end_time == "" ]]; then
printf "${BOLD}${RED}Usage: $0 <filename> <output name> <start time HH:MM:SS> <end time HH:MM:SS>${NORMAL}\n"
exit 1
fi
extension="${filename##*.}"
filename="${filename%.*}"
output="${output_name}.$extension"
timing_args="-ss $start_time -to $end_time"
printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n"
ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -i "$filename.$extension" -c:v libx264 -c:a copy "$output"
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"

View File

@@ -40,7 +40,7 @@ timing_args="-ss $start_time -to $end_time"
printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n" printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n"
ffmpeg -y -stats -loglevel level+error $timing_args -i "$filename.$extension" -c:a copy -c:v copy "$output" ffmpeg -y -stats -loglevel level+error $timing_args -i "$filename.$extension" -c copy "$output"
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n" printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"

View File

@@ -2,8 +2,8 @@
# If you're getting signature errors, check out https://www.msys2.org/news/#2020-06-29-new-packagers and/or other news posts. # If you're getting signature errors, check out https://www.msys2.org/news/#2020-06-29-new-packagers and/or other news posts.
source "$HOME/.dotfiles/script_helpers/printing.sh" source "$HOME/dotfiles/script_helpers/printing.sh"
source "$HOME/.dotfiles/script_helpers/platform.sh" source "$HOME/dotfiles/script_helpers/platform.sh"
set -e set -e

89
install → dotfiles/install Executable file → Normal file
View File

@@ -4,7 +4,7 @@ if [[ $(uname) == 'Darwin' ]]; then
if ! command -v brew &>/dev/null if ! command -v brew &>/dev/null
then then
# We need to update bash, so we'll start with setting up homebrew. # We need to update bash, so we'll start with setting up homebrew.
./osx/pre_install ./macos/pre_install
exit exit
fi fi
fi fi
@@ -52,31 +52,6 @@ setup_zsh() {
if [[ $is_linux -eq 1 ]]; then if [[ $is_linux -eq 1 ]]; then
sudo apt install zsh sudo apt install zsh
fi fi
make_link .dotfiles/zsh/core .zsh
FILES=()
FILES+=('zshrc')
FILES+=('zlogin')
for file in "${FILES[@]}"
do
make_link .dotfiles/zsh/$file .$file
done
}
setup_bash() {
printf "${MAGENTA}==> ${NORMAL}Setting up bash...\n"
FILES=()
FILES+=('bashrc')
FILES+=('bash_profile')
FILES+=('inputrc')
for file in "${FILES[@]}"
do
make_link .dotfiles/bash/$file .$file
done
} }
#################################################################################################### ####################################################################################################
@@ -85,40 +60,6 @@ setup_bash() {
pushd "$HOME" &>/dev/null pushd "$HOME" &>/dev/null
make_link $dotfiles_dir .dotfiles 1 # expand source path in case we're reinstalling and the cwd is a symlink.
if [[ $is_windows -eq 1 ]]; then
do_vim_copy=1
if [[ -d "$PWD/.vim" ]]; then
printf "\n${BOLD}Vim folder already found at destination. Overwrite? [1,0]\n> ${NORMAL}"
read -e copy_vim
if [[ $copy_vim != "0" && $copy_vim != "1" ]]; then
fatal "Invalid value '$copy_vim'"
elif [[ $copy_vim == "0" ]]; then
do_vim_copy=0
printf "\n"
fi
fi
if [[ $do_vim_copy -eq 1 ]]; then
printf "${MAGENTA}==> ${NORMAL}Copying ${YELLOW}.dotfiles/vim${NORMAL} to ${YELLOW}$PWD/.vim${NORMAL}\n"
cp -r .dotfiles/vim .vim
fi
else
make_link .dotfiles/vim .vim
fi
FILES=()
FILES+=('env.loader')
FILES+=('aliases')
FILES+=('gitconfig')
FILES+=('vimrc')
FILES+=('curlrc')
for file in "${FILES[@]}"
do
make_link .dotfiles/$file .$file
done
set +e set +e
git_comp_filename=".git-completion.bash" git_comp_filename=".git-completion.bash"
printf "${MAGENTA}==> ${NORMAL}Downloading Git completion list to ${YELLOW}$PWD/$git_comp_filename${NORMAL}\n" printf "${MAGENTA}==> ${NORMAL}Downloading Git completion list to ${YELLOW}$PWD/$git_comp_filename${NORMAL}\n"
@@ -129,37 +70,19 @@ set -e
# Setup platform files # Setup platform files
######################### #########################
if [[ $is_windows -eq 1 ]]; then if [[ $is_macos -eq 1 ]]; then
printf "\n${BOLD}Setting up Windows${NORMAL}\n\n"
os_name="windows"
# Already using bash if running msys2.
setup_bash
elif [[ $is_macos -eq 1 ]]; then
printf "\n${BOLD}Setting up MacOS${NORMAL}\n\n" printf "\n${BOLD}Setting up MacOS${NORMAL}\n\n"
os_name="osx" $dotfiles_dir/macos/install
# might just switch back to bash since the zsh stuff is ancient.
setup_zsh setup_zsh
setup_bash
use_shell zsh use_shell zsh
elif [[ $is_linux -eq 1 ]]; then elif [[ $is_linux -eq 1 ]]; then
printf "\n${BOLD}Setting up Linux${NORMAL}\n\n" printf "\n${BOLD}Setting up Linux${NORMAL}\n\n"
os_name="linux" $dotfiles_dir/linux/install
setup_zsh
setup_bash
use_shell bash use_shell bash
fi fi
if [[ $os_name != "" ]]; then
if [ -f .dotfiles/$os_name/env.platform ]; then
make_link .dotfiles/$os_name/env.platform .env.platform
fi
if [ -f .dotfiles/$os_name/gitconfig.platform ]; then
make_link .dotfiles/$os_name/gitconfig.platform .gitconfig.platform
fi
$dotfiles_dir/$os_name/install
fi
popd "$HOME" &>/dev/null popd "$HOME" &>/dev/null
printf "${BOLD}${GREEN}Done!${NORMAL}\n" printf "${BOLD}${GREEN}Done!${NORMAL}\n"

Some files were not shown because too many files have changed in this diff Show More