Compare commits
19 Commits
2019-01-20
...
2019-03-02
Author | SHA1 | Date | |
---|---|---|---|
71264172f2 | |||
8da5be2c19 | |||
9d46615a56 | |||
aaea526054 | |||
13257f07e6 | |||
fc101fb30b | |||
45aac4e39b | |||
bbfff16b44 | |||
43013af49f | |||
475eaebd96 | |||
f5f598a020 | |||
7a29ec5e10 | |||
a528211d3b | |||
f8dd68edc0 | |||
4569e97200 | |||
8c064a13b2 | |||
04aade74eb | |||
24c4ae781b | |||
2e6c398cd1 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
*.pkg.tar.xz*
|
*.pkg.tar.xz*
|
||||||
helper-scripts
|
helper-scripts
|
||||||
|
helper-scripts.spec
|
||||||
PKGBUILD
|
PKGBUILD
|
||||||
pkg
|
pkg
|
||||||
src
|
src
|
||||||
|
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()
|
||||||
|
96
dlaudio.py
Executable file → Normal file
96
dlaudio.py
Executable file → Normal file
@ -1,65 +1,59 @@
|
|||||||
#!/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 shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# =========== Constants ==========
|
||||||
parser = argparse.ArgumentParser()
|
YOUTUBE_DL_BIN = shutil.which('youtube-dl')
|
||||||
parser.add_argument('-b', '--batch-dl',
|
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||||
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()
|
|
||||||
|
|
||||||
default_filename = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
# ========== Error Codes ==========
|
||||||
|
E_NOURLS = 2
|
||||||
|
|
||||||
dl_opts = []
|
# ========== Main Script ==========
|
||||||
dl_opts.append('--no-part')
|
parser = argparse.ArgumentParser()
|
||||||
dl_opts.append('--no-continue')
|
parser.add_argument('-b', '--batchfile',
|
||||||
dl_opts.append('--extract-audio')
|
help='provide the links from a text file')
|
||||||
dl_opts.append(f"--audio-format={args.format}")
|
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}")
|
dl_opts.append(f"--output={args.filename}")
|
||||||
|
else:
|
||||||
|
dl_opts.append(f"--output={DEFAULT_FILENAME}")
|
||||||
|
|
||||||
# filename handling
|
# URL handling
|
||||||
# -b and -n should not be used together
|
if args.batchfile is not None:
|
||||||
if args.filename and args.batchfile:
|
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||||
print('Ignoring --batch-dl and --filename')
|
elif args.urls is not None:
|
||||||
dl_opts.append(f"--output={default_filename}")
|
dl_opts.extend(args.urls)
|
||||||
elif args.filename:
|
else:
|
||||||
dl_opts.append(f"--output={pathlib.Path.home()}/Music/{args.filename}.%(ext)s")
|
print("URLs are required")
|
||||||
else:
|
exit(E_NOURLS)
|
||||||
dl_opts.append(f"--output={default_filename}")
|
|
||||||
|
|
||||||
# URL handling
|
subprocess.run(dl_opts)
|
||||||
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)
|
|
||||||
|
|
||||||
dl = subprocess.run(['youtube-dl'] + 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 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).stdout
|
||||||
text=True)
|
return float(temp)
|
||||||
return float(dump_cmd.stdout)
|
|
||||||
|
|
||||||
|
|
||||||
def convert_to_celsius(mkel_temp):
|
def convert_to_celsius(mkel_temp):
|
||||||
@ -48,17 +51,17 @@ 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')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
dev = args.device
|
dev = args.device
|
||||||
|
|
||||||
if verify_device_node(dev):
|
if verify_device_node(dev):
|
||||||
mkel = retrieve_smart_temp(dev)
|
mkel = retrieve_smart_temp(dev)
|
||||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||||
else:
|
else:
|
||||||
print("Not a device node.")
|
print("Not a device node.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
175
fedit.py
Normal file
175
fedit.py
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
#!/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 = '/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 ==========
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
editor = None
|
||||||
|
|
||||||
|
if editor_override is not None:
|
||||||
|
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:
|
||||||
|
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('patterns',
|
||||||
|
type=str,
|
||||||
|
nargs='*',
|
||||||
|
help='patterns to pass to locate')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
final_find_cmd = [FIND_CMD] + FIND_OPTS
|
||||||
|
editor = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
editor = select_editor(args.editor)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(e)
|
||||||
|
exit(E_NOEDITORFOUND)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
selected_file = run_fzf(files)
|
||||||
|
|
||||||
|
if not selected_file == '':
|
||||||
|
cmd = gen_editor_cmd(selected_file)
|
||||||
|
subprocess.run(cmd)
|
||||||
|
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
|
#!/usr/bin/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)
|
||||||
# - 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,13 +4,14 @@
|
|||||||
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')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
location = args.location
|
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
|
#!/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
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#compdef cptemplate
|
#compdef cptemplate
|
||||||
|
|
||||||
# zsh completions for 'cptemplate'
|
# ========== Completions ==========
|
||||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
arguments=(
|
arguments=(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#compdef dlaudio
|
#compdef dlaudio
|
||||||
|
|
||||||
# zsh completions for 'dlaudio'
|
# zsh completions for 'dlaudio'
|
||||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
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
|
#compdef open
|
||||||
|
|
||||||
# zsh completions for 'open'
|
# ========== Completions ==========
|
||||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
arguments=(
|
arguments=(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#compdef quickdel
|
#compdef quickdel
|
||||||
|
|
||||||
# zsh completions for 'quickdel'
|
# ========== Completions ==========
|
||||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
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
|
# Fuzzy cd from anywhere
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# - fzf
|
# * fzf
|
||||||
# - mlocate
|
# * mlocate
|
||||||
|
|
||||||
|
# ========== Shortcuts ==========
|
||||||
cf() {
|
cf() {
|
||||||
[[ -z "${*}" ]] && return 1
|
[[ -z "${*}" ]] && return 1
|
||||||
[[ ! -x /usr/bin/fzf ]] && 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() {
|
_fedit() {
|
||||||
/usr/bin/fedit
|
/usr/bin/fedit
|
||||||
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
_etcedit() {
|
_etcedit() {
|
||||||
/usr/bin/fedit -e
|
/usr/bin/fedit --etc
|
||||||
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N fedit
|
zle -N _fedit
|
||||||
bindkey -M viins '^o' _fedit
|
bindkey -M viins '^o' _fedit
|
||||||
|
|
||||||
zle -N _etcedit
|
zle -N _etcedit
|
@ -1,6 +1,7 @@
|
|||||||
# key bindings for fless script
|
# Fuzzy-find a file and open it in less
|
||||||
fless() {
|
fless() {
|
||||||
/usr/bin/fless
|
/usr/bin/fless
|
||||||
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N fless
|
zle -N fless
|
Reference in New Issue
Block a user