Compare commits
5 Commits
2019-01-20
...
2019-02-12
Author | SHA1 | Date | |
---|---|---|---|
4569e97200 | |||
8c064a13b2 | |||
04aade74eb | |||
24c4ae781b | |||
2e6c398cd1 |
0
audiotrim.sh
Executable file → Normal file
0
audiotrim.sh
Executable file → Normal file
9
ddusb.py
Executable file → Normal file
9
ddusb.py
Executable file → Normal file
@ -2,14 +2,15 @@
|
||||
"""Write an ISO image to a usb drive using dd."""
|
||||
|
||||
import argparse
|
||||
import configparser
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
# TODO add a config file for blacklisting certain devices e.g. /dev/sda
|
||||
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-b", "--bs", default=512, help="block size", metavar="bs")
|
||||
parser.add_argument("-b", "--bs",
|
||||
default=512,
|
||||
help="block size",
|
||||
metavar="bs")
|
||||
parser.add_argument("input_file", help="input file to write")
|
||||
parser.add_argument("output_file", help="output block device")
|
||||
args = parser.parse_args()
|
||||
|
97
dlaudio.py
Executable file → Normal file
97
dlaudio.py
Executable file → Normal file
@ -1,65 +1,60 @@
|
||||
#!/usr/bin/python3
|
||||
"""Download audio using youtube-dl, passing
|
||||
a specific set of options specified by the user.
|
||||
"""Download audio using youtube-dl.
|
||||
|
||||
=====
|
||||
Usage
|
||||
=====
|
||||
>>> dlaudio -f flac -n <filename> "<url>"
|
||||
Dependencies:
|
||||
=============
|
||||
* youtube-dl
|
||||
"""
|
||||
|
||||
# TODO add support for downloading in flac, and then reencoding it
|
||||
# in opus
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batch-dl',
|
||||
dest='batchfile',
|
||||
type=str,
|
||||
help='provide the links from a text file')
|
||||
parser.add_argument('-f', '--format',
|
||||
type=str,
|
||||
default='flac',
|
||||
help='the format to use')
|
||||
parser.add_argument('-n', '--filename',
|
||||
type=str,
|
||||
help='the name of the downloaded file (without extension)')
|
||||
parser.add_argument('urls',
|
||||
nargs='*',
|
||||
help='video URLs')
|
||||
args = parser.parse_args()
|
||||
# =========== Constants ==========
|
||||
YOUTUBE_DL_BIN = '/usr/bin/youtube-dl'
|
||||
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||
|
||||
default_filename = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||
# ========== Error Codes ==========
|
||||
E_NOURLS = 2
|
||||
|
||||
dl_opts = []
|
||||
dl_opts.append('--no-part')
|
||||
dl_opts.append('--no-continue')
|
||||
dl_opts.append('--extract-audio')
|
||||
dl_opts.append(f"--audio-format={args.format}")
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batchfile',
|
||||
type=str,
|
||||
nargs=1,
|
||||
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.append(f"--output={args.filename}")
|
||||
dl_opts = [YOUTUBE_DL_BIN,
|
||||
'--no-part',
|
||||
'--no-continue',
|
||||
'--extract-audio',
|
||||
'--audio-format={args.format}']
|
||||
|
||||
# filename handling
|
||||
# -b and -n should not be used together
|
||||
if args.filename and args.batchfile:
|
||||
print('Ignoring --batch-dl and --filename')
|
||||
dl_opts.append(f"--output={default_filename}")
|
||||
elif args.filename:
|
||||
dl_opts.append(f"--output={pathlib.Path.home()}/Music/{args.filename}.%(ext)s")
|
||||
else:
|
||||
dl_opts.append(f"--output={default_filename}")
|
||||
# filename handling
|
||||
# if -b is used, DEFAULT_FILENAME must take precedence
|
||||
if args.filename:
|
||||
dl_opts.append('--output={args.filename}')
|
||||
else:
|
||||
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||
|
||||
# URL handling
|
||||
if args.batchfile:
|
||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||
elif len(args.urls) == 0:
|
||||
print("URLs are required")
|
||||
exit(2)
|
||||
else:
|
||||
dl_opts.extend(args.urls)
|
||||
# URL handling
|
||||
if args.batchfile:
|
||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||
elif not args.urls:
|
||||
print("URLs are required")
|
||||
exit(E_NOURLS)
|
||||
else:
|
||||
dl_opts.extend(args.urls)
|
||||
|
||||
dl = subprocess.run(['youtube-dl'] + dl_opts)
|
||||
subprocess.run(dl_opts)
|
||||
|
37
drivetemp.py
Executable file → Normal file
37
drivetemp.py
Executable file → Normal file
@ -13,7 +13,11 @@ import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
# ========== Constants ==========
|
||||
DUMP_CMD = ['skdump', '--temperature']
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
def verify_device_node(query):
|
||||
"""Check if query is a device node.
|
||||
:param query: input that refers to a device
|
||||
@ -31,11 +35,10 @@ def retrieve_smart_temp(device_node):
|
||||
:returns: output of skdump in mKelvin
|
||||
:rtype: float
|
||||
"""
|
||||
dump_cmd = subprocess.run(['sudo', 'skdump', '--temperature',
|
||||
device_node],
|
||||
capture_output=True,
|
||||
text=True)
|
||||
return float(dump_cmd.stdout)
|
||||
temp = subprocess.run(DUMP_CMD + device_node,
|
||||
capture_output=True,
|
||||
text=True).stdout
|
||||
return float(temp)
|
||||
|
||||
|
||||
def convert_to_celsius(mkel_temp):
|
||||
@ -48,17 +51,17 @@ def convert_to_celsius(mkel_temp):
|
||||
return (mkel_temp/1000) - 273.15
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device', help='device node to retrieve\
|
||||
the temperature for', metavar='dev')
|
||||
args = parser.parse_args()
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device', help='device node to retrieve\
|
||||
the temperature for', metavar='dev')
|
||||
args = parser.parse_args()
|
||||
|
||||
dev = args.device
|
||||
dev = args.device
|
||||
|
||||
if verify_device_node(dev):
|
||||
mkel = retrieve_smart_temp(dev)
|
||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||
else:
|
||||
print("Not a device node.")
|
||||
exit(1)
|
||||
if verify_device_node(dev):
|
||||
mkel = retrieve_smart_temp(dev)
|
||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||
else:
|
||||
print("Not a device node.")
|
||||
exit(1)
|
||||
|
106
fedit.py
Normal file
106
fedit.py
Normal file
@ -0,0 +1,106 @@
|
||||
#!/usr/bin/python3
|
||||
"""
|
||||
Fuzzy-find a file and edit it.
|
||||
|
||||
Dependencies
|
||||
============
|
||||
* fd
|
||||
* fzf
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
# ========== Constants ==========
|
||||
# Paths
|
||||
BOOT_DIR = '/boot'
|
||||
ETC_DIR = '/etc'
|
||||
|
||||
# Exit Codes
|
||||
E_NOEDITORFOUND = 2
|
||||
E_NOFILESELECTED = 3
|
||||
|
||||
# Commands
|
||||
FIND_CMD = shutil.which('fd')
|
||||
FIND_OPTS = ['--hidden', '--print0', '--type', 'f', '--no-ignore-vcs']
|
||||
FZF_CMD = shutil.which('fzf')
|
||||
FZF_OPTS = ['--read0', '--select-1', '--exit-0']
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
def select_editor(editor_override=None):
|
||||
"""Return a possible canonical path to an editor.
|
||||
Select an editor from one of:
|
||||
* -e, --editor
|
||||
* $EDITOR
|
||||
* Default of vim
|
||||
|
||||
In this order
|
||||
|
||||
If an editor cannot be resolved, then an Error is raised instead.
|
||||
|
||||
:param editor_override: argument to override an editor
|
||||
:returns: path to one of these editors
|
||||
:rtype: str
|
||||
:raises: FileNotFoundError if an editor could not be resolved
|
||||
"""
|
||||
if editor_override is not None:
|
||||
return shutil.which(editor_override)
|
||||
elif 'EDITOR' in os.environ:
|
||||
return shutil.which(os.environ.get('EDITOR'))
|
||||
elif shutil.which('vim') is not None:
|
||||
return shutil.which('vim')
|
||||
else:
|
||||
raise FileNotFoundError('An editor could not be resolved')
|
||||
|
||||
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--boot',
|
||||
action='store_const',
|
||||
const=BOOT_DIR,
|
||||
dest='dir',
|
||||
help='edit a file in /boot')
|
||||
parser.add_argument('-d', '--dir',
|
||||
dest='dir',
|
||||
type=str,
|
||||
help='edit a file in a given directory')
|
||||
parser.add_argument('-E', '--etc',
|
||||
action='store_const',
|
||||
const=ETC_DIR,
|
||||
dest='dir',
|
||||
help='edit a file in /etc')
|
||||
parser.add_argument('-e', '--editor',
|
||||
help='use a given editor')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
final_find_cmd = [FIND_CMD] + FIND_OPTS
|
||||
extra_opts = []
|
||||
editor = ''
|
||||
|
||||
try:
|
||||
editor = select_editor(args.editor)
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
exit(E_NOEDITORFOUND)
|
||||
|
||||
if args.dir is not None:
|
||||
extra_opts.extend(['.', '--', args.dir])
|
||||
|
||||
final_find_cmd.extend(extra_opts)
|
||||
|
||||
files = subprocess.run(final_find_cmd,
|
||||
text=True,
|
||||
capture_output=True)
|
||||
filename = subprocess.run([FZF_CMD] + FZF_OPTS,
|
||||
input=files.stdout,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE).stdout
|
||||
|
||||
if filename is not None:
|
||||
subprocess.run([editor, filename.strip('\n')])
|
||||
else:
|
||||
exit(E_NOFILESELECTED)
|
132
fedit.sh
132
fedit.sh
@ -1,132 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
# fedit - fuzzy find a file and edit it
|
||||
# Dependencies
|
||||
# - fd
|
||||
# - fzf
|
||||
|
||||
help() {
|
||||
cat << EOF
|
||||
Usage: fedit [-h|--help] [-b|--boot] [-d|--dir directory] [-e|--etc] [-E|--editor editor]
|
||||
Options:
|
||||
-b, --boot edit a file in /boot/loader
|
||||
-d, --dir edit a file in a given directory
|
||||
-e, --etc edit a file in /etc
|
||||
-E, --editor use a given editor (default: ${EDITOR:-none})
|
||||
-h, --help print this help page
|
||||
EOF
|
||||
}
|
||||
|
||||
[[ ! -f /usr/bin/fzf ]] && exit 1
|
||||
|
||||
# Error messages
|
||||
readonly directory_error="Error, enter a directory"
|
||||
readonly noeditor_error="Error, no editor entered"
|
||||
|
||||
# Pre-run correctness checks
|
||||
unset find_opts
|
||||
file=
|
||||
dir=
|
||||
editor=
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
'-b'|'--boot')
|
||||
dir="/boot/loader"
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
'-d'|'--dir')
|
||||
case "${2}" in
|
||||
"")
|
||||
printf '%s\n' "${directory_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
dir="${2}"
|
||||
[[ ! -d "${dir}" ]] && printf '%s\n' "Not a directory: ${dir}" >&2 && exit 1
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--dir=*)
|
||||
dir="${1#*=}"
|
||||
[[ -z "${dir}" ]] && printf '%s\n' "${directory_error}" >&2 && exit 1
|
||||
[[ ! -d "${dir}" ]] && printf '%s\n' "Not a directory: ${dir}" >&2 && exit 1
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
'-e'|'--etc')
|
||||
dir='/etc'
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
'-E'|'--editor')
|
||||
editor="${2}"
|
||||
case "${2}" in
|
||||
"")
|
||||
printf '%s\n' "${noeditor_error}" >&2
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
printf '%s\n' "Not an editor: ${editor}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--editor=*)
|
||||
editor="${1#*=}"
|
||||
[[ -z "${editor}" ]] && printf '%s\n' "${noeditor_error}" >&2 && exit 1
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
'-h'|'--help')
|
||||
help
|
||||
exit
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
printf '%s\n' "Unknown option: ${1}"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
declare -a find_opts
|
||||
if [[ -x '/usr/bin/fd' ]]; then
|
||||
find_bin='/usr/bin/fd'
|
||||
find_opts+=('--hidden')
|
||||
find_opts+=('--print0')
|
||||
find_opts+=('--type' 'f')
|
||||
find_opts+=('--no-ignore-vcs')
|
||||
[[ -n "${dir}" ]] && find_opts+=('.' -- "${dir}")
|
||||
else
|
||||
find_bin='/usr/bin/find'
|
||||
[[ -n "${dir}" ]] && find_opts+=("${dir}") || find_opts+=('.')
|
||||
find_opts+=('-mindepth' '0')
|
||||
find_opts+=('-type' 'f')
|
||||
find_opts+=('-print0')
|
||||
fi
|
||||
|
||||
if [[ -z "${editor:-${EDITOR}}" ]]; then
|
||||
printf '%s\n' "No editor found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file="$("${find_bin}" "${find_opts[@]}" 2> /dev/null | fzf --read0 --select-1 --exit-0)"
|
||||
|
||||
[[ ! "${file}" ]] && exit 1
|
||||
|
||||
if [[ -w "${file}" ]]; then
|
||||
"${editor:-${EDITOR}}" -- "${file}"
|
||||
else
|
||||
sudo --edit -- "${file}"
|
||||
fi
|
8
fless.sh
Executable file → Normal file
8
fless.sh
Executable file → Normal file
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/bash
|
||||
# fless - fuzzy find a file and run less on it
|
||||
# Dependencies
|
||||
# - fd (soft)
|
||||
# - fzf
|
||||
# - fd (soft)
|
||||
# - fzf
|
||||
|
||||
_help() {
|
||||
help() {
|
||||
cat << EOF
|
||||
Usage: fless [-h|--help] [-b|--boot] [-d|--dir directory] [-e|--etc]
|
||||
Options:
|
||||
@ -58,7 +58,7 @@ while true; do
|
||||
continue
|
||||
;;
|
||||
'-h'|'--help')
|
||||
printHelp
|
||||
help
|
||||
exit
|
||||
;;
|
||||
--)
|
||||
|
@ -4,13 +4,14 @@
|
||||
import argparse
|
||||
import requests
|
||||
|
||||
# ========== Constants ==========
|
||||
WTTR_URI = 'http://wttr.in'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('location')
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('location')
|
||||
|
||||
args = parser.parse_args()
|
||||
location = args.location
|
||||
args = parser.parse_args()
|
||||
location = args.location
|
||||
|
||||
print(requests.get(f"{WTTR_URI}/{location}").text)
|
||||
print(requests.get(f"{WTTR_URI}/{location}").text)
|
||||
|
@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
# quickdel - delete any file matching a query
|
||||
# Dependencies:
|
||||
# fd
|
||||
## quickdel - delete any file matching a query
|
||||
## Dependencies:
|
||||
## * bash
|
||||
## * fd
|
||||
|
||||
printHelp() {
|
||||
cat << EOF
|
||||
@ -65,7 +66,7 @@ while true; do
|
||||
done
|
||||
|
||||
# Prevent fd from selecting everything
|
||||
[[ -z "${*}" ]] && printf '%s\n' "No queries entered, cancelling" >&2 && exit 1
|
||||
[[ -z "${@}" ]] && printf '%s\n' "No queries entered, cancelling" >&2 && exit 1
|
||||
|
||||
for pattern in "${@}"; do
|
||||
while IFS= read -r -d '' file; do
|
||||
|
Reference in New Issue
Block a user