Compare commits
15 Commits
2019-02-12
...
2019-03-07
Author | SHA1 | Date | |
---|---|---|---|
3ec9989f25 | |||
71264172f2 | |||
8da5be2c19 | |||
9d46615a56 | |||
aaea526054 | |||
13257f07e6 | |||
fc101fb30b | |||
45aac4e39b | |||
bbfff16b44 | |||
43013af49f | |||
475eaebd96 | |||
f5f598a020 | |||
7a29ec5e10 | |||
a528211d3b | |||
f8dd68edc0 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
*.pkg.tar.xz*
|
||||
helper-scripts
|
||||
helper-scripts.spec
|
||||
PKGBUILD
|
||||
pkg
|
||||
src
|
||||
|
21
ddusb.py
21
ddusb.py
@ -7,10 +7,7 @@ import subprocess
|
||||
|
||||
# ========== 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()
|
||||
@ -28,11 +25,17 @@ print(f"Block device: {block_device}")
|
||||
print(f"Block size: {block_size}")
|
||||
|
||||
try:
|
||||
subprocess.run(["dd", f"if={input_file}",
|
||||
f"of={block_device}",
|
||||
f"bs={block_size}",
|
||||
"status=progress"], check=True)
|
||||
subprocess.run(
|
||||
[
|
||||
"dd",
|
||||
f"if={input_file}",
|
||||
f"of={block_device}",
|
||||
f"bs={block_size}",
|
||||
"status=progress",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
exit(1)
|
||||
else:
|
||||
subprocess.run(['sync'])
|
||||
subprocess.run(["sync"])
|
||||
|
51
dlaudio.py
51
dlaudio.py
@ -8,10 +8,11 @@ Dependencies:
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
# =========== Constants ==========
|
||||
YOUTUBE_DL_BIN = '/usr/bin/youtube-dl'
|
||||
YOUTUBE_DL_BIN = shutil.which("youtube-dl")
|
||||
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||
|
||||
# ========== Error Codes ==========
|
||||
@ -19,42 +20,38 @@ E_NOURLS = 2
|
||||
|
||||
# ========== 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')
|
||||
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',
|
||||
'--audio-format={args.format}']
|
||||
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:
|
||||
dl_opts.append('--output={args.filename}')
|
||||
if args.filename is not None and args.batchfile is None:
|
||||
dl_opts.append(f"--output={args.filename}")
|
||||
else:
|
||||
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||
dl_opts.append(f"--output={DEFAULT_FILENAME}")
|
||||
|
||||
# URL handling
|
||||
if args.batchfile:
|
||||
if args.batchfile is not None:
|
||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||
elif not args.urls:
|
||||
elif args.urls is not None:
|
||||
dl_opts.extend(args.urls)
|
||||
else:
|
||||
print("URLs are required")
|
||||
exit(E_NOURLS)
|
||||
else:
|
||||
dl_opts.extend(args.urls)
|
||||
|
||||
subprocess.run(dl_opts)
|
||||
|
18
drivetemp.py
18
drivetemp.py
@ -14,7 +14,7 @@ import pathlib
|
||||
import subprocess
|
||||
|
||||
# ========== Constants ==========
|
||||
DUMP_CMD = ['skdump', '--temperature']
|
||||
DUMP_CMD = ["skdump", "--temperature"]
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
@ -35,9 +35,9 @@ def retrieve_smart_temp(device_node):
|
||||
:returns: output of skdump in mKelvin
|
||||
:rtype: float
|
||||
"""
|
||||
temp = subprocess.run(DUMP_CMD + device_node,
|
||||
capture_output=True,
|
||||
text=True).stdout
|
||||
temp = subprocess.run(
|
||||
DUMP_CMD + [device_node], capture_output=True, text=True
|
||||
).stdout
|
||||
return float(temp)
|
||||
|
||||
|
||||
@ -48,13 +48,17 @@ def convert_to_celsius(mkel_temp):
|
||||
:returns: temperature converted into degrees celsius
|
||||
:rtype: str
|
||||
"""
|
||||
return (mkel_temp/1000) - 273.15
|
||||
return (mkel_temp / 1000) - 273.15
|
||||
|
||||
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device', help='device node to retrieve\
|
||||
the temperature for', metavar='dev')
|
||||
parser.add_argument(
|
||||
"device",
|
||||
help="device node to retrieve\
|
||||
the temperature for",
|
||||
metavar="dev",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
dev = args.device
|
||||
|
156
fedit.py
156
fedit.py
@ -15,18 +15,22 @@ import subprocess
|
||||
|
||||
# ========== Constants ==========
|
||||
# Paths
|
||||
BOOT_DIR = '/boot'
|
||||
ETC_DIR = '/etc'
|
||||
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']
|
||||
FIND_CMD = "/usr/bin/fd"
|
||||
FIND_OPTS = ["--hidden", "--print0", "--type", "f", "--no-ignore-vcs"]
|
||||
FZF_CMD = "/usr/bin/fzf"
|
||||
FZF_OPTS = ["--read0", "--select-1", "--exit-0", "--print0"]
|
||||
LOCATE_CMD = "/usr/bin/locate"
|
||||
LOCATE_OPTS = ["--all", "--ignore-case", "--null"]
|
||||
|
||||
LOCALE = "utf-8"
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
@ -46,40 +50,109 @@ def select_editor(editor_override=None):
|
||||
:rtype: str
|
||||
:raises: FileNotFoundError if an editor could not be resolved
|
||||
"""
|
||||
editor = None
|
||||
|
||||
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')
|
||||
editor = shutil.which(editor_override)
|
||||
elif "EDITOR" in os.environ:
|
||||
editor = shutil.which(os.environ.get("EDITOR"))
|
||||
elif shutil.which("vim") is not None:
|
||||
editor = shutil.which("vim")
|
||||
|
||||
if editor is None:
|
||||
raise FileNotFoundError("An editor could not be resolved")
|
||||
|
||||
return editor
|
||||
|
||||
|
||||
def gen_editor_cmd(filename):
|
||||
"""Generate a command line to run for editing a file based on
|
||||
permissions.
|
||||
|
||||
:param filename: name of file to edit
|
||||
:type filename: str or path-like object
|
||||
:returns: command to execute to edit file
|
||||
:rtype: list
|
||||
"""
|
||||
# possible for a race condition to occur here
|
||||
if os.access(filename, os.W_OK):
|
||||
return [editor, filename]
|
||||
else:
|
||||
raise FileNotFoundError('An editor could not be resolved')
|
||||
return ["sudo", "--edit", filename]
|
||||
|
||||
|
||||
def run_fzf(files):
|
||||
"""Run fzf on a stream of searched files for the user to select.
|
||||
|
||||
:param files: stream of null-terminated files to read
|
||||
:type files: bytes stream (stdout of a completed process)
|
||||
:returns: selected file
|
||||
:rtype: str
|
||||
"""
|
||||
selected_file = subprocess.run(
|
||||
[FZF_CMD] + FZF_OPTS, input=files, stdout=subprocess.PIPE
|
||||
).stdout
|
||||
|
||||
return selected_file.decode(LOCALE).strip("\x00")
|
||||
|
||||
|
||||
def find_files(directory=None):
|
||||
"""Use a find-based program to locate files, then pass to fzf.
|
||||
|
||||
:param directory: directory to search for files
|
||||
:type directory: str
|
||||
:returns: path of user-selected file
|
||||
:rtype: bytes
|
||||
"""
|
||||
cmd = [FIND_CMD] + FIND_OPTS
|
||||
if directory is not None:
|
||||
cmd.extend(["--", ".", directory])
|
||||
|
||||
return subprocess.run(cmd, capture_output=True).stdout
|
||||
|
||||
|
||||
def locate_files(patterns):
|
||||
"""Use a locate-based program to locate files, then pass to fzf.
|
||||
|
||||
:param patterns: patterns to pass to locate
|
||||
:type patterns: list
|
||||
:returns: path of user-selected file
|
||||
:rtype: bytes
|
||||
"""
|
||||
cmd = [LOCATE_CMD] + LOCATE_OPTS
|
||||
cmd.extend(patterns)
|
||||
|
||||
return subprocess.run(cmd, capture_output=True).stdout
|
||||
|
||||
|
||||
# ========== 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')
|
||||
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")
|
||||
parser.add_argument("patterns", type=str, nargs="*", help="patterns to pass to locate")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
final_find_cmd = [FIND_CMD] + FIND_OPTS
|
||||
extra_opts = []
|
||||
editor = ''
|
||||
editor = ""
|
||||
|
||||
try:
|
||||
editor = select_editor(args.editor)
|
||||
@ -87,20 +160,17 @@ except FileNotFoundError as e:
|
||||
print(e)
|
||||
exit(E_NOEDITORFOUND)
|
||||
|
||||
if args.dir is not None:
|
||||
extra_opts.extend(['.', '--', args.dir])
|
||||
# If patterns were passed, use locate
|
||||
# Otherwise check for -d and use fd
|
||||
if not args.patterns == []:
|
||||
files = locate_files(args.patterns)
|
||||
else:
|
||||
files = find_files(args.dir)
|
||||
|
||||
final_find_cmd.extend(extra_opts)
|
||||
selected_file = run_fzf(files)
|
||||
|
||||
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')])
|
||||
if not selected_file == "":
|
||||
cmd = gen_editor_cmd(selected_file)
|
||||
subprocess.run(cmd)
|
||||
else:
|
||||
exit(E_NOFILESELECTED)
|
||||
|
@ -5,11 +5,11 @@ import argparse
|
||||
import requests
|
||||
|
||||
# ========== Constants ==========
|
||||
WTTR_URI = 'http://wttr.in'
|
||||
WTTR_URI = "http://wttr.in"
|
||||
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('location')
|
||||
parser.add_argument("location")
|
||||
|
||||
args = parser.parse_args()
|
||||
location = args.location
|
||||
|
@ -1,7 +1,6 @@
|
||||
#compdef cptemplate
|
||||
|
||||
# zsh completions for 'cptemplate'
|
||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||
# ========== Completions ==========
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
|
@ -1,7 +1,6 @@
|
||||
#compdef dlaudio
|
||||
|
||||
# zsh completions for 'dlaudio'
|
||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
|
14
zsh/completions/_fedit
Normal file
14
zsh/completions/_fedit
Normal file
@ -0,0 +1,14 @@
|
||||
#compdef fedit
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
$argument_list
|
||||
{-h, --help}'[show this help message and exit]'
|
||||
{-b, --boot}'[edit a file in /boot]'
|
||||
{-d, --dir}'[edit a file in a given directory]'
|
||||
{-E, --etc}'[edit a file in /etc]'
|
||||
{-e, --editor}'[use a given editor]'
|
||||
'*:filename:_files'
|
||||
)
|
||||
|
||||
_arguments -s $arguments
|
@ -1,7 +1,6 @@
|
||||
#compdef open
|
||||
|
||||
# zsh completions for 'open'
|
||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||
# ========== Completions ==========
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
|
@ -1,7 +1,6 @@
|
||||
#compdef quickdel
|
||||
|
||||
# zsh completions for 'quickdel'
|
||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||
# ========== Completions ==========
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
|
@ -1,79 +0,0 @@
|
||||
# ef - fuzzy find a file and edit it
|
||||
# Dependencies
|
||||
# - fzf
|
||||
# - mlocate
|
||||
|
||||
_ef_help() {
|
||||
cat << done
|
||||
Usage: ef [-h|--help] [-E|--editor editor] [patterns]
|
||||
|
||||
Options:
|
||||
-h print this help page
|
||||
-E, --editor use a different editor (default: ${EDITOR:-none})
|
||||
done
|
||||
}
|
||||
|
||||
ef() {
|
||||
# Pre-run correctness checks
|
||||
editor=
|
||||
file=
|
||||
|
||||
while true; do
|
||||
case "${1}" in
|
||||
"-E"|"--editor")
|
||||
case "${2}" in
|
||||
""|-*)
|
||||
printf '%s\n' "Not an editor or none entered" >&2
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
editor="${2}"
|
||||
;;
|
||||
esac
|
||||
shift 2
|
||||
continue
|
||||
;;
|
||||
--editor=*)
|
||||
editor="${1#*=}"
|
||||
[[ -z "${editor}" ]] && printf '%s\n' "Editor not entered" >&2 && return 1
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
"-h"|"--help")
|
||||
_ef_help
|
||||
return
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-?)
|
||||
printf '%s\n' "Unknown option: ${1}" >&2
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "${editor:-${EDITOR}}" ]]; then
|
||||
printf '%s\n' "No editor found" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
file="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --exit-0 --select-1 --no-mouse)"
|
||||
|
||||
if [[ -z "${file}" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -w "${file}" ]]; then
|
||||
"${editor:-${EDITOR}}" -- "${file}"
|
||||
else
|
||||
sudo --edit -- "${file}"
|
||||
fi
|
||||
}
|
||||
|
||||
#zle -N ef
|
||||
#bindkey -M viins '^o' ef
|
@ -1,7 +1,9 @@
|
||||
# Fuzzy cd from anywhere
|
||||
# Dependencies
|
||||
# - fzf
|
||||
# - mlocate
|
||||
# * fzf
|
||||
# * mlocate
|
||||
|
||||
# ========== Shortcuts ==========
|
||||
cf() {
|
||||
[[ -z "${*}" ]] && return 1
|
||||
[[ ! -x /usr/bin/fzf ]] && return 1
|
@ -1,13 +1,16 @@
|
||||
# call the fedit script
|
||||
# Fuzzy find a file and then edit it
|
||||
|
||||
_fedit() {
|
||||
/usr/bin/fedit
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
_etcedit() {
|
||||
/usr/bin/fedit -e
|
||||
/usr/bin/fedit --etc
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
zle -N fedit
|
||||
zle -N _fedit
|
||||
bindkey -M viins '^o' _fedit
|
||||
|
||||
zle -N _etcedit
|
@ -1,6 +1,7 @@
|
||||
# key bindings for fless script
|
||||
# Fuzzy-find a file and open it in less
|
||||
fless() {
|
||||
/usr/bin/fless
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
zle -N fless
|
Reference in New Issue
Block a user