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."""
|
"""Write an ISO image to a usb drive using dd."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# TODO add a config file for blacklisting certain devices e.g. /dev/sda
|
# ========== Main Script ==========
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
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("input_file", help="input file to write")
|
||||||
parser.add_argument("output_file", help="output block device")
|
parser.add_argument("output_file", help="output block device")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
61
dlaudio.py
Executable file → Normal file
61
dlaudio.py
Executable file → Normal file
@ -1,65 +1,60 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
"""Download audio using youtube-dl, passing
|
"""Download audio using youtube-dl.
|
||||||
a specific set of options specified by the user.
|
|
||||||
|
|
||||||
=====
|
Dependencies:
|
||||||
Usage
|
=============
|
||||||
=====
|
* youtube-dl
|
||||||
>>> dlaudio -f flac -n <filename> "<url>"
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO add support for downloading in flac, and then reencoding it
|
|
||||||
# in opus
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# =========== Constants ==========
|
||||||
|
YOUTUBE_DL_BIN = '/usr/bin/youtube-dl'
|
||||||
|
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||||
|
|
||||||
|
# ========== Error Codes ==========
|
||||||
|
E_NOURLS = 2
|
||||||
|
|
||||||
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-b', '--batch-dl',
|
parser.add_argument('-b', '--batchfile',
|
||||||
dest='batchfile',
|
|
||||||
type=str,
|
type=str,
|
||||||
|
nargs=1,
|
||||||
help='provide the links from a text file')
|
help='provide the links from a text file')
|
||||||
parser.add_argument('-f', '--format',
|
parser.add_argument('-f', '--format',
|
||||||
type=str,
|
type=str,
|
||||||
default='flac',
|
default='opus',
|
||||||
help='the format to use')
|
help='the format to use')
|
||||||
parser.add_argument('-n', '--filename',
|
parser.add_argument('-n', '--filename',
|
||||||
type=str,
|
type=str,
|
||||||
help='the name of the downloaded file (without extension)')
|
help='downloaded filename (without extension)')
|
||||||
parser.add_argument('urls',
|
parser.add_argument('urls',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
help='video URLs')
|
help='video URLs')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
default_filename = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
dl_opts = [YOUTUBE_DL_BIN,
|
||||||
|
'--no-part',
|
||||||
dl_opts = []
|
'--no-continue',
|
||||||
dl_opts.append('--no-part')
|
'--extract-audio',
|
||||||
dl_opts.append('--no-continue')
|
'--audio-format={args.format}']
|
||||||
dl_opts.append('--extract-audio')
|
|
||||||
dl_opts.append(f"--audio-format={args.format}")
|
|
||||||
|
|
||||||
dl_opts.append(f"--output={args.filename}")
|
|
||||||
|
|
||||||
# filename handling
|
# filename handling
|
||||||
# -b and -n should not be used together
|
# if -b is used, DEFAULT_FILENAME must take precedence
|
||||||
if args.filename and args.batchfile:
|
if args.filename:
|
||||||
print('Ignoring --batch-dl and --filename')
|
dl_opts.append('--output={args.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:
|
else:
|
||||||
dl_opts.append(f"--output={default_filename}")
|
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||||
|
|
||||||
# URL handling
|
# URL handling
|
||||||
if args.batchfile:
|
if args.batchfile:
|
||||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||||
elif len(args.urls) == 0:
|
elif not args.urls:
|
||||||
print("URLs are required")
|
print("URLs are required")
|
||||||
exit(2)
|
exit(E_NOURLS)
|
||||||
else:
|
else:
|
||||||
dl_opts.extend(args.urls)
|
dl_opts.extend(args.urls)
|
||||||
|
|
||||||
dl = subprocess.run(['youtube-dl'] + dl_opts)
|
subprocess.run(dl_opts)
|
||||||
|
13
drivetemp.py
Executable file → Normal file
13
drivetemp.py
Executable file → Normal file
@ -13,7 +13,11 @@ import argparse
|
|||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# ========== Constants ==========
|
||||||
|
DUMP_CMD = ['skdump', '--temperature']
|
||||||
|
|
||||||
|
|
||||||
|
# ========== Functions ==========
|
||||||
def verify_device_node(query):
|
def verify_device_node(query):
|
||||||
"""Check if query is a device node.
|
"""Check if query is a device node.
|
||||||
:param query: input that refers to a device
|
:param query: input that refers to a device
|
||||||
@ -31,11 +35,10 @@ def retrieve_smart_temp(device_node):
|
|||||||
:returns: output of skdump in mKelvin
|
:returns: output of skdump in mKelvin
|
||||||
:rtype: float
|
:rtype: float
|
||||||
"""
|
"""
|
||||||
dump_cmd = subprocess.run(['sudo', 'skdump', '--temperature',
|
temp = subprocess.run(DUMP_CMD + device_node,
|
||||||
device_node],
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True)
|
text=True).stdout
|
||||||
return float(dump_cmd.stdout)
|
return float(temp)
|
||||||
|
|
||||||
|
|
||||||
def convert_to_celsius(mkel_temp):
|
def convert_to_celsius(mkel_temp):
|
||||||
@ -48,7 +51,7 @@ def convert_to_celsius(mkel_temp):
|
|||||||
return (mkel_temp/1000) - 273.15
|
return (mkel_temp/1000) - 273.15
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('device', help='device node to retrieve\
|
parser.add_argument('device', help='device node to retrieve\
|
||||||
the temperature for', metavar='dev')
|
the temperature for', metavar='dev')
|
||||||
|
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
|
|
4
fless.sh
Executable file → Normal file
4
fless.sh
Executable file → Normal file
@ -4,7 +4,7 @@
|
|||||||
# - fd (soft)
|
# - fd (soft)
|
||||||
# - fzf
|
# - fzf
|
||||||
|
|
||||||
_help() {
|
help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: fless [-h|--help] [-b|--boot] [-d|--dir directory] [-e|--etc]
|
Usage: fless [-h|--help] [-b|--boot] [-d|--dir directory] [-e|--etc]
|
||||||
Options:
|
Options:
|
||||||
@ -58,7 +58,7 @@ while true; do
|
|||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
'-h'|'--help')
|
'-h'|'--help')
|
||||||
printHelp
|
help
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# ========== Constants ==========
|
||||||
WTTR_URI = 'http://wttr.in'
|
WTTR_URI = 'http://wttr.in'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('location')
|
parser.add_argument('location')
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# quickdel - delete any file matching a query
|
## quickdel - delete any file matching a query
|
||||||
# Dependencies:
|
## Dependencies:
|
||||||
# fd
|
## * bash
|
||||||
|
## * fd
|
||||||
|
|
||||||
printHelp() {
|
printHelp() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
@ -65,7 +66,7 @@ while true; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Prevent fd from selecting everything
|
# 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
|
for pattern in "${@}"; do
|
||||||
while IFS= read -r -d '' file; do
|
while IFS= read -r -d '' file; do
|
||||||
|
Reference in New Issue
Block a user