Compare commits
No commits in common. "master" and "2019-03-09" have entirely different histories.
master
...
2019-03-09
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
*.pkg.tar.xz*
|
*.pkg.tar.xz*
|
||||||
helper-scripts
|
helper-scripts
|
||||||
helper-scripts.rb
|
|
||||||
helper-scripts.spec
|
helper-scripts.spec
|
||||||
PKGBUILD
|
PKGBUILD
|
||||||
pkg
|
pkg
|
||||||
|
48
audiotrim.sh
Normal file
48
audiotrim.sh
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/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}"}"
|
@ -1,3 +1,4 @@
|
|||||||
# File for excluding block devices from being written to
|
# File for excluding block devices from being written to
|
||||||
# One rule per line, regular expressions are accepted i.e. /dev/sda[0-9]?
|
# Write one device per line, shell-style globs are accepted i.e. /dev/sda*
|
||||||
|
# Brace expansion is not supported
|
||||||
# Lines beginning with "#" and ";" are ignored
|
# Lines beginning with "#" and ";" are ignored
|
||||||
|
62
cptemplate.sh
Normal file
62
cptemplate.sh
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
# Copy a file from ~/Templates to a given name
|
||||||
|
#
|
||||||
|
# Dependencies:
|
||||||
|
# - fd (soft)
|
||||||
|
# - fzf
|
||||||
|
|
||||||
|
printHelp() {
|
||||||
|
cat << EOF
|
||||||
|
Usage: cptemplate [-h,--help] [options] [filename]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help print 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
|
||||||
|
|
||||||
|
# check for existence of fd and fzf binaries
|
||||||
|
if [[ ! -x '/usr/bin/fzf' ]]; then
|
||||||
|
printf '%s\n' 'fzf is not installed on the system'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare -a find_opts
|
||||||
|
template_dir="${HOME}/Templates"
|
||||||
|
|
||||||
|
if [[ -x '/usr/bin/fd' ]]; then
|
||||||
|
find_bin='/usr/bin/fd'
|
||||||
|
find_opts+=('--print0')
|
||||||
|
find_opts+=('--type' 'f')
|
||||||
|
find_opts+=('.' "${template_dir}")
|
||||||
|
else
|
||||||
|
find_bin='/usr/bin/find'
|
||||||
|
find_opts+=("${template_dir}")
|
||||||
|
find_opts+=('-mindepth' '0')
|
||||||
|
find_opts+=('-type' 'f')
|
||||||
|
find_opts+=('-print0')
|
||||||
|
fi
|
||||||
|
|
||||||
|
template_file="$("${find_bin}" "${find_opts[@]}" | fzf --read0 --select-1 --exit-0 --no-mouse)"
|
||||||
|
[[ -z "${template_file}" ]] && exit 1
|
||||||
|
|
||||||
|
cp --interactive --verbose "${template_file}" "${1:-.}"
|
55
ddusb.py
Executable file → Normal file
55
ddusb.py
Executable file → Normal file
@ -1,20 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/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
|
||||||
import os
|
import glob
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# ========== Constants ==========
|
# ========== Constants ==========
|
||||||
COMMENT_PATTERN = r"^[#;]"
|
COMMENT_PATTERN = "^[#;]"
|
||||||
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
|
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
|
||||||
|
|
||||||
E_BLOCKDEVICE_ERROR = 1
|
|
||||||
E_EXCLUDE_ERROR = 2
|
|
||||||
E_DD_ERROR = 3
|
|
||||||
|
|
||||||
|
|
||||||
# ========== Functions ==========
|
# ========== Functions ==========
|
||||||
def read_exclude_file(exclude_file):
|
def read_exclude_file(exclude_file):
|
||||||
@ -37,6 +33,23 @@ def read_exclude_file(exclude_file):
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
def expand_globs(*globs):
|
||||||
|
"""For each glob given, expand these globs and return a list
|
||||||
|
containing each glob expanded.
|
||||||
|
|
||||||
|
:param globs: patterns to expand
|
||||||
|
:type globs: str
|
||||||
|
:returns: all expanded globs aggregated together
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
expanded_globs = []
|
||||||
|
|
||||||
|
for line in globs:
|
||||||
|
expanded_globs.extend(glob.glob(line, recursive=True))
|
||||||
|
|
||||||
|
return expanded_globs
|
||||||
|
|
||||||
|
|
||||||
# ========== Main Script ==========
|
# ========== 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")
|
||||||
@ -46,23 +59,23 @@ args = parser.parse_args()
|
|||||||
|
|
||||||
block_size = args.bs
|
block_size = args.bs
|
||||||
input_file = args.input_file
|
input_file = args.input_file
|
||||||
block_path = args.output_file
|
block_device = args.output_file
|
||||||
|
|
||||||
# Ensure that block_path is really a block device
|
# Ensure that block_device is really a block device
|
||||||
if not pathlib.Path(block_path).is_block_device():
|
if not pathlib.Path(block_device).is_block_device():
|
||||||
print(f'Error: "{block_path}" is not a block device')
|
print(f'Error: "{block_device}" is not a block device')
|
||||||
exit(E_BLOCKDEVICE_ERROR)
|
exit(1)
|
||||||
|
|
||||||
# Check if block_path is excluded
|
# Check if block_device is excluded
|
||||||
exclude_patterns = read_exclude_file(EXCLUDE_FILE)
|
exclude_patterns = read_exclude_file(EXCLUDE_FILE)
|
||||||
|
device_blacklist = expand_globs(*exclude_patterns)
|
||||||
|
|
||||||
for pattern in exclude_patterns:
|
if block_device in device_blacklist:
|
||||||
if re.fullmatch(pattern, block_path):
|
print(f'Error: "{block_device}" is blacklisted from running dd')
|
||||||
print(f'Error: "{block_path}" is blacklisted from running dd')
|
exit(2)
|
||||||
exit(E_EXCLUDE_ERROR)
|
|
||||||
|
|
||||||
print(f"Input file: {input_file}")
|
print(f"Input file: {input_file}")
|
||||||
print(f"Block device: {block_path}")
|
print(f"Block device: {block_device}")
|
||||||
print(f"Block size: {block_size}")
|
print(f"Block size: {block_size}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -70,13 +83,13 @@ try:
|
|||||||
[
|
[
|
||||||
"dd",
|
"dd",
|
||||||
f"if={input_file}",
|
f"if={input_file}",
|
||||||
f"of={block_path}",
|
f"of={block_device}",
|
||||||
f"bs={block_size}",
|
f"bs={block_size}",
|
||||||
"status=progress",
|
"status=progress",
|
||||||
],
|
],
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
exit(E_DD_ERROR)
|
exit(3)
|
||||||
else:
|
else:
|
||||||
os.sync()
|
subprocess.run("sync")
|
||||||
|
57
dlaudio.py
Normal file
57
dlaudio.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/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
Executable file → Normal file
7
drivetemp.py
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/python3
|
||||||
"""Check the temperature of a drive.
|
"""Check the temperature of a drive.
|
||||||
Functions:
|
Functions:
|
||||||
verify_device_node(query)
|
verify_device_node(query)
|
||||||
@ -54,7 +54,10 @@ def convert_to_celsius(mkel_temp):
|
|||||||
# ========== Main Script ==========
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"device", help="device node to retrieve the temperature for", metavar="dev"
|
"device",
|
||||||
|
help="device node to retrieve\
|
||||||
|
the temperature for",
|
||||||
|
metavar="dev",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
176
fedit.py
Normal file
176
fedit.py
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
#!/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)
|
2
fless.sh
Executable file → Normal file
2
fless.sh
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env 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)
|
||||||
|
2
gek.sh
Executable file → Normal file
2
gek.sh
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/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
Executable file → Normal file
2
getweather.py
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/python3
|
||||||
"""Obtain a weather forecast."""
|
"""Obtain a weather forecast."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
2
lsgroups.sh
Executable file → Normal file
2
lsgroups.sh
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/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
Executable file → Normal file
2
lsusers.sh
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/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)
|
||||||
|
2
open.sh
Executable file → Normal file
2
open.sh
Executable file → Normal file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/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:
|
||||||
|
96
quickdel.sh
Normal file
96
quickdel.sh
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
## quickdel - delete any file matching a query
|
||||||
|
## Dependencies:
|
||||||
|
## * bash
|
||||||
|
## * fd
|
||||||
|
|
||||||
|
printHelp() {
|
||||||
|
cat << EOF
|
||||||
|
Fuzzy find and delete files matching patterns
|
||||||
|
|
||||||
|
Usage: quickdel [-h] [-i] [-I] [patterns]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-d, --directories-only only delete directories
|
||||||
|
-h, --help print this help page
|
||||||
|
-i, --no-ignore do not ignore .gitignore and .fdignore
|
||||||
|
-I, --no--ignore-vcs do not ignore .gitignore
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pre-run correctness checks
|
||||||
|
unset files
|
||||||
|
unset fd_opts
|
||||||
|
ans=
|
||||||
|
|
||||||
|
declare -a files
|
||||||
|
declare -a fd_opts
|
||||||
|
declare -r blue='\033[0;34m'
|
||||||
|
declare -r nocolor='\033[0;0m'
|
||||||
|
|
||||||
|
[[ ! -x '/usr/bin/fd' ]] && echo 'fd is not present, cancelling' >&2 && exit 1
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "${1}" in
|
||||||
|
'-d'|'--directories-only')
|
||||||
|
fd_opts+=('--type' 'd')
|
||||||
|
shift
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
'-h'|'--help')
|
||||||
|
printHelp
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
'-i'|'--no-ignore')
|
||||||
|
fd_opts+=('--no-ignore')
|
||||||
|
shift
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
'-I'|'--no-ignore-vcs')
|
||||||
|
fd_opts+=('--no-ignore-vcs')
|
||||||
|
shift
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
printf '%s\n' "Unknown option: ${1}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Prevent fd from selecting everything
|
||||||
|
[[ -z "${@}" ]] && printf '%s\n' "No queries entered, cancelling" >&2 && exit 1
|
||||||
|
|
||||||
|
for pattern in "${@}"; do
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
files+=("${file}")
|
||||||
|
done < <(fd --hidden --print0 "${fd_opts[@]}" -- "${pattern}")
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -z "${files[*]}" ]] && printf '%s\n' "No results found" >&2 && exit 1
|
||||||
|
|
||||||
|
# List all filenames, pretty print them
|
||||||
|
for filename in "${files[@]}"; do
|
||||||
|
if [[ -f "${filename}" ]]; then
|
||||||
|
printf '%s\n' "${filename}"
|
||||||
|
elif [[ -d "${filename}" ]]; then
|
||||||
|
printf '%b%s%b\n' "${blue}" "${filename}" "${nocolor}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
printf '%s' "Would you like to delete these files? "
|
||||||
|
read -r -n 1 ans
|
||||||
|
|
||||||
|
if [[ "${ans:-n}" =~ (Y|y) ]]; then
|
||||||
|
rm --recursive --force -- "${files[@]}"
|
||||||
|
else
|
||||||
|
printf '\n%s\n' "Operation cancelled" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
@ -1,6 +1,7 @@
|
|||||||
#compdef ddusb
|
#compdef ddusb
|
||||||
|
|
||||||
# zsh completions for 'ddusb'
|
# zsh completions for 'ddusb'
|
||||||
|
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||||
local arguments
|
local arguments
|
||||||
|
|
||||||
arguments=(
|
arguments=(
|
||||||
|
14
zsh/completions/_dlaudio
Normal file
14
zsh/completions/_dlaudio
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#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
|
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
|
14
zsh/completions/_quickdel
Normal file
14
zsh/completions/_quickdel
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#compdef quickdel
|
||||||
|
|
||||||
|
# ========== Completions ==========
|
||||||
|
local arguments
|
||||||
|
|
||||||
|
arguments=(
|
||||||
|
{-d,--directories-only}'[only delete directories]'
|
||||||
|
{-h,--help}'[print this help page]'
|
||||||
|
{-i,--no-ignore}'[do not ignore .gitignore and .fdignore]'
|
||||||
|
{-I,--no-ignore-vcs}'[do not ignore .gitignore]'
|
||||||
|
'*:filename:_files'
|
||||||
|
)
|
||||||
|
|
||||||
|
_arguments -s $arguments
|
22
zsh/plugins/cf.zsh
Normal file
22
zsh/plugins/cf.zsh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# 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
|
15
zsh/plugins/fedit.zsh
Normal file
15
zsh/plugins/fedit.zsh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# 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
|
7
zsh/plugins/fless.zsh
Normal file
7
zsh/plugins/fless.zsh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Fuzzy-find a file and open it in less
|
||||||
|
fless() {
|
||||||
|
/usr/bin/fless && zle reset-prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
zle -N fless
|
||||||
|
bindkey -M viins '^n' fless
|
8
zsh/plugins/mkcd.zsh
Normal file
8
zsh/plugins/mkcd.zsh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Make a directory, then change into it
|
||||||
|
|
||||||
|
mkcd() {
|
||||||
|
[[ ! -d "${1}" ]] && mkdir --parents -- "${1}"
|
||||||
|
cd "${1}" || exit
|
||||||
|
}
|
||||||
|
|
||||||
|
autoload -Uz mkcd
|
Loading…
x
Reference in New Issue
Block a user