16 Commits

Author SHA1 Message Date
6b595f44a3 Use env to account for PATH interpreter precedence 2020-06-22 11:21:19 -07:00
144190b1c9 Revert "Change interpreter from #!/usr/bin/bash to #!/bin/bash"
This reverts commit 9c776c3400.
2020-06-22 11:17:29 -07:00
bd729e5372 Ignore homebrew package file 2020-06-22 11:16:51 -07:00
9c776c3400 Change interpreter from #!/usr/bin/bash to #!/bin/bash 2020-06-22 11:06:05 -07:00
09a53e2681 Remove zsh plugin files 2020-06-22 10:50:33 -07:00
129ca17ccd Rename zsh widgets to avoid confusion 2020-06-21 23:17:18 -07:00
3bf21a54e6 Revert "Rename zsh plugins so they are detected by zsh"
This reverts commit 4890ff8aaa.
2020-06-21 22:53:45 -07:00
4890ff8aaa Rename zsh plugins so they are detected by zsh 2020-06-21 22:49:10 -07:00
5537227fc0 Don't use absolute path when calling fedit script in plugin 2020-06-21 22:06:16 -07:00
79ccd05105 Make fedit script OS agnostic with respect to program cmd line flags 2020-06-07 15:24:36 -07:00
bdf236d067 Fix file permissions for entire repository 2020-06-07 04:38:56 -07:00
bfdf513154 drivetemp: minor code formatting change 2019-11-03 20:50:05 -08:00
c377f57173 Split audio helper scripts into its own package 2019-07-07 07:16:57 -07:00
343df18c83 Pass %(ext)s when filename is provided on command line 2019-06-17 20:49:12 -07:00
b6d2c0b38b Remove unused shutil import 2019-06-17 20:38:23 -07:00
a39f4c9c51 General script cleanup 2019-04-17 21:42:19 -07:00
20 changed files with 34 additions and 190 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.pkg.tar.xz* *.pkg.tar.xz*
helper-scripts helper-scripts
helper-scripts.rb
helper-scripts.spec helper-scripts.spec
PKGBUILD PKGBUILD
pkg pkg

View File

@ -1,48 +0,0 @@
#!/usr/bin/bash
# Trim an audio file given a startpoint and an endpoint
# Dependencies: ffmpeg
printHelp() {
cat << EOF
Usage: audiotrim [input file] [start time] [stop time] [output file]
Options:
-h show this help page
EOF
}
while true; do
case "${1}" in
'-h'|'--help')
printHelp
exit
;;
--)
shift
break
;;
-*)
printf '%s\n' "Unknown option: ${1}"
exit 1
;;
*)
break
;;
esac
done
if [[ ! -x '/usr/bin/ffmpeg' ]]; then
printf '%s\n' 'ffmpeg program is not installed' >&2
exit 1
fi
readonly infile="${1}"
readonly starttime="${2}"
readonly stoptime="${3}"
readonly outfile="${4}"
readonly format="${1%.*}"
[[ -z "${infile}" ]] && printf '%s\n' "No file entered." >&2 exit 2
[[ ! -f "${infile}" ]] && printf '%s\n' "Not a file: ${infile}" >&2 exit 3
ffmpeg -i "${infile}" -ss "${starttime}" -to "${stoptime}" -c copy "${outfile:-"${outfile%.*}-trimmed.${format}"}"

2
cptemplate.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# Copy a file from ~/Templates to a given name # Copy a file from ~/Templates to a given name
# #
# Dependencies: # Dependencies:

2
ddusb.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
"""Wrapper script for using dd to write to a USB drive.""" """Wrapper script for using dd to write to a USB drive."""
import argparse import argparse

View File

@ -1,57 +0,0 @@
#!/usr/bin/python3
"""Download audio using youtube-dl.
Dependencies:
=============
* youtube-dl
"""
import argparse
import pathlib
import shutil
import subprocess
# =========== Constants ==========
YOUTUBE_DL_BIN = shutil.which("youtube-dl")
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
# ========== Error Codes ==========
E_NOURLS = 2
# ========== Main Script ==========
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--batchfile", help="provide the links from a text file")
parser.add_argument(
"-f", "--format", type=str, default="opus", help="the format to use"
)
parser.add_argument(
"-n", "--filename", type=str, help="downloaded filename (without extension)"
)
parser.add_argument("urls", nargs="*", help="video URLs")
args = parser.parse_args()
dl_opts = [
YOUTUBE_DL_BIN,
"--no-part",
"--no-continue",
"--extract-audio",
f"--audio-format={args.format}",
]
# filename handling
# if -b is used, DEFAULT_FILENAME must take precedence
if args.filename is not None and args.batchfile is None:
dl_opts.append(f"--output={args.filename}")
else:
dl_opts.append(f"--output={DEFAULT_FILENAME}")
# URL handling
if args.batchfile is not None:
dl_opts.append(f"--batch-file={args.batchfile}")
elif args.urls is not None:
dl_opts.extend(args.urls)
else:
print("URLs are required")
exit(E_NOURLS)
subprocess.run(dl_opts)

7
drivetemp.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
"""Check the temperature of a drive. """Check the temperature of a drive.
Functions: Functions:
verify_device_node(query) verify_device_node(query)
@ -54,10 +54,7 @@ def convert_to_celsius(mkel_temp):
# ========== Main Script ========== # ========== Main Script ==========
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"device", "device", help="device node to retrieve the temperature for", metavar="dev"
help="device node to retrieve\
the temperature for",
metavar="dev",
) )
args = parser.parse_args() args = parser.parse_args()

27
fedit.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
""" """
Fuzzy-find a file and edit it. Fuzzy-find a file and edit it.
@ -13,6 +13,8 @@ import os
import shutil import shutil
import subprocess import subprocess
from sys import platform
# ========== Constants ========== # ========== Constants ==========
# ----- Paths ----- # ----- Paths -----
BOOT_DIR = "/boot" BOOT_DIR = "/boot"
@ -24,16 +26,27 @@ E_NOEDITORFOUND = 2
E_NOFILESELECTED = 3 E_NOFILESELECTED = 3
# ----- Commands ----- # ----- Commands -----
FIND_CMD = "/usr/bin/fd"
# Options: show hidden files, null terminator, files only
# Optional arguments: show vcs files, show every file
FIND_CMD = shutil.which("fd")
FIND_OPTS = ["--hidden", "--print0", "--type", "f"] FIND_OPTS = ["--hidden", "--print0", "--type", "f"]
EXTRA_FIND_OPTS = {"no_ignore_vcs": "--no-ignore", "no_ignore": "--no-ignore-vcs"} EXTRA_FIND_OPTS = {"no_ignore_vcs": "--no-ignore", "no_ignore": "--no-ignore-vcs"}
LOCATE_CMD = "/usr/bin/locate" # Options: null terminator, ignore case, print names matching all non-option arguments
LOCATE_OPTS = ["--all", "--ignore-case", "--null"] LOCATE_CMD = shutil.which("locate")
FZF_CMD = "/usr/bin/fzf" # Options: read null terminator, auto-select if one option, exit if no options, print null terminator
FZF_CMD = shutil.which("fzf")
FZF_OPTS = ["--read0", "--select-1", "--exit-0", "--print0"] FZF_OPTS = ["--read0", "--select-1", "--exit-0", "--print0"]
# Platform-specific options
# macOS doesn't support GNU-style long options
if platform == "linux":
LOCATE_OPTS = ["--all", "--ignore-case", "--null"]
elif platform == "darwin":
LOCATE_OPTS = ["-0", "-i"]
# ----- Misc. ----- # ----- Misc. -----
LOCALE = "utf-8" LOCALE = "utf-8"
@ -139,6 +152,10 @@ def locate_files(patterns):
# ========== Main Script ========== # ========== Main Script ==========
if __name__ == "__main__": if __name__ == "__main__":
# This script doesn't support Windows
if platform == "windows":
sys.exit(E_INTERRUPT)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"-b", "-b",

2
fless.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# fless - fuzzy find a file and run less on it # fless - fuzzy find a file and run less on it
# Dependencies # Dependencies
# - fd (soft) # - fd (soft)

2
gek.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# Export a key to a given keyfile # Export a key to a given keyfile
echo -n "Enter the name of the output file: " echo -n "Enter the name of the output file: "

2
getweather.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
"""Obtain a weather forecast.""" """Obtain a weather forecast."""
import argparse import argparse

2
lsgroups.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# List all groups in the system # List all groups in the system
sort <(awk -F ':' '{print $1}' < /etc/group) sort <(awk -F ':' '{print $1}' < /etc/group)

2
lsusers.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# List all users on the system # List all users on the system
sort --unique <(awk -F ':' '{print $1}' < /etc/passwd) sort --unique <(awk -F ':' '{print $1}' < /etc/passwd)

0
misc/quickdel.sh Normal file → Executable file
View File

2
open.sh Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/env bash
# open - fuzzy find, select, and open a file using xdg-open # open - fuzzy find, select, and open a file using xdg-open
# #
# Dependencies: # Dependencies:

2
quickdel.py Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
""" """
quickdel - delete any file matching a query quickdel - delete any file matching a query

View File

@ -1,14 +0,0 @@
#compdef dlaudio
# zsh completions for 'dlaudio'
local arguments
arguments=(
{-h,--help}'[show this help message and exit]'
{-b,--batch-dl}'[provide the links from a text file]'
{-f,--format}'[the format to use (default:flac)]'
{-n,--filename}'[the name of the downloaded file (without extension)]'
'*:filename:_files'
)
_arguments -s $arguments

View File

@ -1,22 +0,0 @@
# Fuzzy cd from anywhere
# Dependencies
# * fzf
# * mlocate
# ========== Shortcuts ==========
cf() {
[[ -z "${*}" ]] && return 1
[[ ! -x /usr/bin/fzf ]] && return 1
dir="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --select-1 --exit-0)"
[[ -z "${dir}" ]] && return 1
if [[ -f "${dir}" ]]; then
cd "${dir%/*}"
else
cd "${dir}"
fi
}
autoload -Uz cf

View File

@ -1,15 +0,0 @@
# Fuzzy find a file and then edit it
_fedit() {
/usr/bin/fedit && zle reset-prompt
}
_etcedit() {
/usr/bin/fedit --etc && zle reset-prompt
}
zle -N _fedit
bindkey -M viins '^o' _fedit
zle -N _etcedit
bindkey -M viins '^e' _etcedit

View File

@ -1,7 +0,0 @@
# Fuzzy-find a file and open it in less
fless() {
/usr/bin/fless && zle reset-prompt
}
zle -N fless
bindkey -M viins '^n' fless

View File

@ -1,8 +0,0 @@
# Make a directory, then change into it
mkcd() {
[[ ! -d "${1}" ]] && mkdir --parents -- "${1}"
cd "${1}" || exit
}
autoload -Uz mkcd