- Minor cleanup
- Change shebangs to use 'env' in prep for NixOS (and others) - `agenda` now has a symlink to the underlying tree structure named ".tree" - `binbox` has more checking, being prepped for automatic export of symlinks. - `cdz` now symlinks to the archive directory using "<archive name>.tmp". This is less confusing than a randomized extraction folder, and adds the benefit of being in the FS-tree of the original archive. - daisy.source changes: > Added basic debug mode. > `ched` can now set global (all of the shell) editor or local (lackadaisical utils only) editor. > The encoding/decoding functions have been expanded and improved. Extra checking, permissions are stored as well, `daisy_dec` can handle stdin. - Added new functions to manage lackadaisical config: daisy_backup (runs `bak` on config files), daisy_clear (removes config files), and daisy_restore (restores config files archived using bak). - All functions/tools prefixed with 'daisy_' are now also available prefixed with 'ld_' instead - Added a new utility, `clip`. This utility keeps a local variable that can be set if given args and get if no args are supplied. Basically a simple clipboard local to the ptty. Supports stdin.
This commit is contained in:
parent
021e4d3b44
commit
160a7763b7
13 changed files with 480 additions and 269 deletions
33
README.md
33
README.md
|
|
@ -64,6 +64,8 @@ These are the included binaries and utilities:
|
||||||
Format is <dir> -> .daisy/<dir>/<year>/<month>/<day>.
|
Format is <dir> -> .daisy/<dir>/<year>/<month>/<day>.
|
||||||
Recommended to run via crontab - automatically cleans
|
Recommended to run via crontab - automatically cleans
|
||||||
up empty folders.
|
up empty folders.
|
||||||
|
A symlink to the base of the folder's tree, ".tree",
|
||||||
|
is created in the root of the specified directly.
|
||||||
Can be used for everything you'd like to sort by date.
|
Can be used for everything you'd like to sort by date.
|
||||||
For example; a diary, browser downloads, backups, code.
|
For example; a diary, browser downloads, backups, code.
|
||||||
- own:
|
- own:
|
||||||
|
|
@ -116,10 +118,23 @@ These are the included binaries and utilities:
|
||||||
Like chsh but for your editor (EDITOR env). A list
|
Like chsh but for your editor (EDITOR env). A list
|
||||||
from which you can choose an installed editor
|
from which you can choose an installed editor
|
||||||
(CLI or GUI) is shown. This list is by no means complete.
|
(CLI or GUI) is shown. This list is by no means complete.
|
||||||
|
The editor for LACKADAISICAL and the global editor are
|
||||||
|
separate. If the EDITOR variable is already defined,
|
||||||
|
only LD_EDITOR will be changed. LD_EDITOR is the editor
|
||||||
|
used by LACKADAISICAL utilities.
|
||||||
|
To override the global EDITOR variable, pass "-g".
|
||||||
|
To restore the normal behavior of checking for an earlier
|
||||||
|
definition of EDITOR after passing "-g", run `ched` without
|
||||||
|
arguments.
|
||||||
- cdf:
|
- cdf:
|
||||||
Use fzf to find a file and then cd to its location.
|
Use fzf to find a file and then cd to its location.
|
||||||
- cdp:
|
- cdp:
|
||||||
Similar to `cdf` but uses tree+peco for the query.
|
Similar to `cdf` but uses tree+peco for the query.
|
||||||
|
- clip:
|
||||||
|
An extremely simple utility that functions as a clipboard of sorts.
|
||||||
|
To set the variable, run "clip <data>" or provide data via stdin.
|
||||||
|
To get the variable, simply run clip without any arguments.
|
||||||
|
The variable is stored locally in the shell as "LD_CLIP".
|
||||||
- ldrc:
|
- ldrc:
|
||||||
Edits daisy.source and re-sources it, similarly to shrc.
|
Edits daisy.source and re-sources it, similarly to shrc.
|
||||||
- daisy_reload:
|
- daisy_reload:
|
||||||
|
|
@ -136,7 +151,10 @@ These are the included binaries and utilities:
|
||||||
decoded by passing the output(s) to `daisy_dec`.
|
decoded by passing the output(s) to `daisy_dec`.
|
||||||
The output of `daisy_enc` can be concatenated with the
|
The output of `daisy_enc` can be concatenated with the
|
||||||
output of another encoded file to create a multi-file
|
output of another encoded file to create a multi-file
|
||||||
base64 archive similar to `daisy_enc_multi`
|
base64 archive similar to `daisy_enc_multi`.
|
||||||
|
Does not support symlinks yet, and will instead treat it
|
||||||
|
as a full input file (reads the data of the linked file).
|
||||||
|
When using stdin, please provide a filename as argument.
|
||||||
- daisy_enc_multi:
|
- daisy_enc_multi:
|
||||||
A version of `daisy_enc` that encodes multiple
|
A version of `daisy_enc` that encodes multiple
|
||||||
files and outputs `daisy_base64_data` blocks to a file
|
files and outputs `daisy_base64_data` blocks to a file
|
||||||
|
|
@ -171,5 +189,18 @@ These are the included binaries and utilities:
|
||||||
`daisy_reload`
|
`daisy_reload`
|
||||||
- daisy_list:
|
- daisy_list:
|
||||||
List all available commands without description.
|
List all available commands without description.
|
||||||
|
- daisy_clear:
|
||||||
|
Removes all configuration, including aliases.
|
||||||
|
A backup is made and can be restored using "daisy_restore".
|
||||||
|
Triggers a reload.
|
||||||
|
- daisy_backup:
|
||||||
|
Backs up all config files. These can be restored using
|
||||||
|
"daisy_restore".
|
||||||
|
- daisy_restore:
|
||||||
|
Undoes "daisy_clear" by restoring config files.
|
||||||
|
Triggers a reload.
|
||||||
|
- ld_*:
|
||||||
|
All functions prefixed by "daisy_" are also available with
|
||||||
|
the prefix "ld_" via aliases provided in daisy.source.
|
||||||
--- END OF DAISY HELP ---
|
--- END OF DAISY HELP ---
|
||||||
```
|
```
|
||||||
|
|
|
||||||
5
agenda
5
agenda
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# This script is intended to be run via cron.
|
# This script is intended to be run via cron.
|
||||||
|
|
||||||
# It creates a folder structure in home for the current date in the following format:
|
# It creates a folder structure in home for the current date in the following format:
|
||||||
|
|
@ -35,7 +35,7 @@ day=$(echo $today | awk -F"-" '{print $3}')
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
function errorFn()
|
function errorFn
|
||||||
{
|
{
|
||||||
error=$?
|
error=$?
|
||||||
if [[ $error -gt 0 ]];
|
if [[ $error -gt 0 ]];
|
||||||
|
|
@ -56,4 +56,5 @@ test -L "$today_sym" && rm -rf "$today_sym"
|
||||||
# Now we can set up today's directory
|
# Now we can set up today's directory
|
||||||
mkdir -p "$root_dir/$year/$month/$day"
|
mkdir -p "$root_dir/$year/$month/$day"
|
||||||
ln -s "$root_dir/$year/$month/$day" "$today_sym"
|
ln -s "$root_dir/$year/$month/$day" "$today_sym"
|
||||||
|
ln -s "$root_dir" "$today_sym/.tree"
|
||||||
exitcode=@?
|
exitcode=@?
|
||||||
|
|
|
||||||
82
binbox
82
binbox
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# binbox: Creates a multi-binary script that self-contains the input scripts.
|
# binbox: Creates a multi-binary script that self-contains the input scripts.
|
||||||
# Symlinking to the resulting binary with the name of one of the original scripts will trigger
|
# Symlinking to the resulting binary with the name of one of the original scripts will trigger
|
||||||
# said script. The idea is similar to `busybox`.
|
# said script. The idea is similar to `busybox`.
|
||||||
|
|
@ -11,6 +11,7 @@ args=$@
|
||||||
function help()
|
function help()
|
||||||
{
|
{
|
||||||
echo "$LD_BIN is a utility that allows you to generate busybox-style combined binaries."
|
echo "$LD_BIN is a utility that allows you to generate busybox-style combined binaries."
|
||||||
|
echo "It only supports shell scripts compatible with \`bash\`."
|
||||||
echo "To access the original functionality of an input binary, you can either use a symlink or"
|
echo "To access the original functionality of an input binary, you can either use a symlink or"
|
||||||
echo "call the function like so: 'combi-bin input-bin <input-bin args>."
|
echo "call the function like so: 'combi-bin input-bin <input-bin args>."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
@ -55,32 +56,51 @@ i=0
|
||||||
b=0
|
b=0
|
||||||
s=0
|
s=0
|
||||||
p=0
|
p=0
|
||||||
|
|
||||||
while [ $i -lt $# ]; do
|
while [ $i -lt $# ]; do
|
||||||
case "${args[$i]}" in
|
case "${args[$i]}" in
|
||||||
-i)
|
-i)
|
||||||
((i++))
|
((i++))
|
||||||
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
||||||
inputs+=("${args[$i]}")
|
file="${args[$i]}"
|
||||||
((i++))
|
((i++))
|
||||||
|
if [[ -e "$file" ]]; then
|
||||||
|
inputs+=("$file")
|
||||||
((b++))
|
((b++))
|
||||||
|
else
|
||||||
|
echo "WARNING: Missing input binary: \"$file\"."
|
||||||
|
echo "Module will NOT be available!"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
-s)
|
-s)
|
||||||
((i++))
|
((i++))
|
||||||
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
||||||
sources+=("${args[$i]}")
|
file="${args[$i]}"
|
||||||
((i++))
|
((i++))
|
||||||
|
if [[ -e "$file" ]]; then
|
||||||
|
sources+=("$file")
|
||||||
((s++))
|
((s++))
|
||||||
|
else
|
||||||
|
echo "WARNING: Missing input source: \"$file\"."
|
||||||
|
echo "File will NOT be sourced!"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
-p)
|
-p)
|
||||||
((i++))
|
((i++))
|
||||||
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
while [ $i -lt $# ] && [[ ! "${args[$i]}" =~ ^- ]]; do
|
||||||
includes+=("${args[$i]}")
|
file="${args[$i]}"
|
||||||
((i++))
|
((i++))
|
||||||
|
if [[ -e "$file" ]]; then
|
||||||
|
includes+=("$file")
|
||||||
((p++))
|
((p++))
|
||||||
|
else
|
||||||
|
echo "WARNING: Missing input include: \"$file\"."
|
||||||
|
echo "File will NOT be included!"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
|
@ -97,11 +117,6 @@ echo "Include files: ${includes[*]}"
|
||||||
echo "Source files: ${sources[*]}"
|
echo "Source files: ${sources[*]}"
|
||||||
echo "Output binary: $output"
|
echo "Output binary: $output"
|
||||||
|
|
||||||
if [ "$b" -eq 0 ]; then
|
|
||||||
echo "Missing input binaries!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$output" == "" ]]; then
|
if [[ "$output" == "" ]]; then
|
||||||
echo "Missing output file!"
|
echo "Missing output file!"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -112,11 +127,16 @@ function add()
|
||||||
echo "$@" >> "$output"
|
echo "$@" >> "$output"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_nn()
|
||||||
|
{
|
||||||
|
echo -n "$@" >> "$output"
|
||||||
|
}
|
||||||
|
|
||||||
rm -rf "$output"
|
rm -rf "$output"
|
||||||
|
|
||||||
# Now to construct the binary
|
# Now to construct the binary
|
||||||
# >>> Section 1, includes
|
# >>> Section 1, includes
|
||||||
add "#!/bin/bash"
|
add "#!/usr/bin/env bash"
|
||||||
add "# Multi-call binary generated by LACKADAISICAL binbox"
|
add "# Multi-call binary generated by LACKADAISICAL binbox"
|
||||||
add "# $output information:"
|
add "# $output information:"
|
||||||
add "# Contained modules: ${inputs[*]}"
|
add "# Contained modules: ${inputs[*]}"
|
||||||
|
|
@ -135,6 +155,7 @@ for f in "${includes[@]}"; do
|
||||||
add "$(cat "$f")"
|
add "$(cat "$f")"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
add "readarray -t all_funcs < <(declare -F | awk '{print \$3}')"
|
||||||
|
|
||||||
# >>> Section 2: Modules
|
# >>> Section 2: Modules
|
||||||
for f in "${inputs[@]}"; do
|
for f in "${inputs[@]}"; do
|
||||||
|
|
@ -146,25 +167,52 @@ for f in "${inputs[@]}"; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# >>> Section 3: Module selection
|
# >>> Section 3: Module selection
|
||||||
|
add ""
|
||||||
|
add "################################################################################"
|
||||||
|
add "# END OF INCLUDED MODULES ######################################################"
|
||||||
|
add "################################################################################"
|
||||||
|
add ""
|
||||||
|
add "# Array of modules as well as array of functions."
|
||||||
|
# Add a static list of modules with a no-newline add
|
||||||
|
add_nn "modules=("
|
||||||
|
for f in "${inputs[@]}"; do
|
||||||
|
add_nn "\"$f\" "
|
||||||
|
done
|
||||||
|
add ")"
|
||||||
|
add 'mapfile -t funcs < <(printf "%s\n" "${all_funcs[@]}" "${modules[@]}" "${modules[@]}" | sort | uniq -u)'
|
||||||
|
add ""
|
||||||
|
add "# Check the export switches (-m and -f)"
|
||||||
|
add ""
|
||||||
|
|
||||||
add "symed=1"
|
add "symed=1"
|
||||||
add "binself=\$(basename \$0)"
|
add "binself=\$(basename \$0)"
|
||||||
add "boxfile=\"$output\""
|
add "boxfile=\"$(basename $output)\""
|
||||||
|
add ""
|
||||||
add "if [[ \$binself == \$boxfile ]]; then"
|
add "if [[ \$binself == \$boxfile ]]; then"
|
||||||
add " symed=0"
|
add " symed=0"
|
||||||
add " if [[ \$# -eq 0 ]]; then"
|
add " if [[ \$# -eq 0 ]]; then"
|
||||||
add " echo 'Available modules:'"
|
add " echo '$(basename $output): Multi-call binary generated by lackadaisical binbox.'"
|
||||||
for f in "${inputs[@]}"; do
|
add " echo 'Use switch \"-m\" to generate symlinks of modules in the current directory,'"
|
||||||
add " echo '$f'"
|
add " echo 'or use switch \"-f\" to generate symlinks of all available functions.'"
|
||||||
done
|
add " echo ''"
|
||||||
|
add " echo 'Exported modules:'"
|
||||||
|
add " for mod in \"\${modules[@]}\"; do"
|
||||||
|
add " echo \"- \$mod\""
|
||||||
|
add " done"
|
||||||
|
add " echo ''"
|
||||||
|
add " echo 'Other functions:'"
|
||||||
|
add " for func in \"\${funcs[@]}\"; do"
|
||||||
|
add " echo \"- \$func\""
|
||||||
|
add " done"
|
||||||
add " exit 0"
|
add " exit 0"
|
||||||
add " fi"
|
add " fi"
|
||||||
add "fi"
|
add "fi"
|
||||||
|
add ""
|
||||||
add "if [[ \$symed -eq 0 ]]; then"
|
add "if [[ \$symed -eq 0 ]]; then"
|
||||||
add " eval \$@"
|
add " eval \$@"
|
||||||
add " exit \$?"
|
add " exit \$?"
|
||||||
add "fi"
|
add "fi"
|
||||||
|
add ""
|
||||||
add "if [[ \$symed -eq 1 ]]; then"
|
add "if [[ \$symed -eq 1 ]]; then"
|
||||||
add " eval \$(basename \$0) \$@"
|
add " eval \$(basename \$0) \$@"
|
||||||
add "fi"
|
add "fi"
|
||||||
|
|
|
||||||
2
calm
2
calm
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Calm a process down
|
# Calm a process down
|
||||||
# NEEDS_WORK: cleanup
|
# NEEDS_WORK: cleanup
|
||||||
# calm <pid> == only one process
|
# calm <pid> == only one process
|
||||||
|
|
|
||||||
22
cdz
22
cdz
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [[ $LD_INTERNAL -ne 1 ]];
|
if [[ $LD_INTERNAL -ne 1 ]];
|
||||||
then
|
then
|
||||||
export LD_INTERNAL=1
|
LD_INTERNAL=1
|
||||||
. $(dirname $(realpath $0))/daisy.source
|
. $(dirname $(realpath $0))/daisy.source
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -28,6 +28,7 @@ hasmounter=$?
|
||||||
file "$target" 1>/dev/null
|
file "$target" 1>/dev/null
|
||||||
exitcode=$?
|
exitcode=$?
|
||||||
report=$(file "$target")
|
report=$(file "$target")
|
||||||
|
name=$(echo $@ | sed 's/:.*//' | sed 's|.*/||')
|
||||||
|
|
||||||
# Check for archive type, supported types are zip/tar/rar
|
# Check for archive type, supported types are zip/tar/rar
|
||||||
comm1=(:)
|
comm1=(:)
|
||||||
|
|
@ -88,7 +89,7 @@ elif (( $israr == 0 )); then
|
||||||
comm3=(exit 1)
|
comm3=(exit 1)
|
||||||
fi
|
fi
|
||||||
elif (( $hasmounter == 0 )); then
|
elif (( $hasmounter == 0 )); then
|
||||||
comm2=(archivemount "$target")
|
comm2=(archivemount -o allow_root -o use_ino "$target")
|
||||||
comm4=(cd ..)
|
comm4=(cd ..)
|
||||||
comm5=(umount)
|
comm5=(umount)
|
||||||
fi
|
fi
|
||||||
|
|
@ -101,18 +102,17 @@ dir=$(mktemp -d /tmp/extracted.XXXXXXXX)
|
||||||
"${comm2[@]}" $dir
|
"${comm2[@]}" $dir
|
||||||
"${comm3[@]}"
|
"${comm3[@]}"
|
||||||
|
|
||||||
currentpath=$(realpath .)
|
currentpath=$(pwd)
|
||||||
cd $dir
|
sym="$currentpath/$name.tmp"
|
||||||
|
ln -f -s "$dir" "$sym"
|
||||||
|
cd "$sym"
|
||||||
|
|
||||||
# With archivemount, making a symlink will alter the archive
|
echo "A symlink has been made under the name \"$sym\"."
|
||||||
if (( $hasmounter == 1 )); then
|
echo "This symlink points to the data directory \"$dir\"."
|
||||||
ln -s $currentpath ./link-back
|
|
||||||
echo "A symlink to your original path has been created under the name \`link-back\`."
|
|
||||||
echo "You can use this to copy out files, but you can also just access your filesystem regularly."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Type 'exit' to exit the extracted archive's folder and auto-delete it."
|
echo "Type 'exit' to exit the extracted archive's folder and auto-delete it."
|
||||||
eval $SHELL
|
eval $SHELL
|
||||||
"${comm4[@]}"
|
"${comm4[@]}"
|
||||||
"${comm5[@]}" $dir
|
"${comm5[@]}" $dir
|
||||||
rm -rf $dir
|
rm -rf $dir
|
||||||
|
rm "$sym"
|
||||||
|
|
|
||||||
517
daisy.source
517
daisy.source
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/echo "This file can only be sourced, not run stand-alone." -- #!/bin/bash
|
#!/usr/bin/env -S echo "This file can only be sourced, not run stand-alone."
|
||||||
# LACKADAISICAL SOURCE-ABLE FILE
|
# LACKADAISICAL SOURCE-ABLE FILE
|
||||||
|
|
||||||
# Source this in your RC file or manually to receive some of the simpler
|
# Source this in your RC file or manually to receive some of the simpler
|
||||||
|
|
@ -11,11 +11,22 @@
|
||||||
# only included if sourced from one of the included scripts, though you are
|
# only included if sourced from one of the included scripts, though you are
|
||||||
# free to bypass this by setting env variable LD_INTERNAL to 1.
|
# free to bypass this by setting env variable LD_INTERNAL to 1.
|
||||||
|
|
||||||
if [[ $LD_INTERNAL -eq 1 ]];
|
# Pass _LD_DEBUG=1 during sourcing to see debug information on a variety of things.
|
||||||
|
|
||||||
|
if [[ $LD_INTERNAL == 1 ]];
|
||||||
then
|
then
|
||||||
export LD_BIN=$(basename $0)
|
export LD_BIN=$(basename $0)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function ld_dbg
|
||||||
|
{
|
||||||
|
if [[ $_LD_DEBUG == 1 ]];
|
||||||
|
then
|
||||||
|
$@
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
# Variables for use in other utilities
|
# Variables for use in other utilities
|
||||||
# Find the right argument for our folder
|
# Find the right argument for our folder
|
||||||
arg=$0
|
arg=$0
|
||||||
|
|
@ -25,24 +36,26 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for dependencies
|
# Check for dependencies
|
||||||
function daisy_dependency_check
|
function _daisy_dependency_check
|
||||||
{
|
{
|
||||||
BIN=$(command -v $1 2>/dev/null)
|
BIN=$(command -v $1 2>/dev/null)
|
||||||
res=$?
|
res=$?
|
||||||
|
|
||||||
BIN=$(basename $BIN 2>/dev/null)
|
|
||||||
|
|
||||||
if [[ $BIN == $1 ]]; then
|
|
||||||
res=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo $(($res ^ 1))
|
echo $(($res ^ 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
LD_HAS_fzf=$(daisy_dependency_check fzf)
|
LD_HAS_fzf=$(_daisy_dependency_check fzf)
|
||||||
LD_HAS_md5sum=$(daisy_dependency_check md5sum)
|
LD_HAS_md5sum=$(_daisy_dependency_check md5sum)
|
||||||
LD_HAS_peco=$(daisy_dependency_check peco)
|
LD_HAS_peco=$(_daisy_dependency_check peco)
|
||||||
LD_HAS_tree=$(daisy_dependency_check tree)
|
LD_HAS_tree=$(_daisy_dependency_check tree)
|
||||||
|
LD_HAS_dialog=$(_daisy_dependency_check dialog)
|
||||||
|
|
||||||
|
ld_dbg echo "Presence of utils:"
|
||||||
|
ld_dbg echo fzf $LD_HAS_fzf
|
||||||
|
ld_dbg echo md5sum $LD_HAS_md5sum
|
||||||
|
ld_dbg echo peco $LD_HAS_peco
|
||||||
|
ld_dbg echo tree $LD_HAS_tree
|
||||||
|
ld_dbg echo dialog $LD_HAS_dialog
|
||||||
|
|
||||||
export LD_FOLDER=$(dirname $(realpath $arg))
|
export LD_FOLDER=$(dirname $(realpath $arg))
|
||||||
export LD_SOURCE_FILE=$(realpath $arg)
|
export LD_SOURCE_FILE=$(realpath $arg)
|
||||||
|
|
@ -67,6 +80,10 @@ LD_EDITORFILE="$LD_CONFIG_FOLDER/editor.src"
|
||||||
touch $LD_ALIASFILE
|
touch $LD_ALIASFILE
|
||||||
touch $LD_EDITORFILE
|
touch $LD_EDITORFILE
|
||||||
|
|
||||||
|
ld_dbg echo "Sourced config contents:"
|
||||||
|
ld_dbg cat $LD_ALIASFILE
|
||||||
|
ld_dbg cat $LD_EDITORFILE
|
||||||
|
|
||||||
# Source everything in the config folder
|
# Source everything in the config folder
|
||||||
function _daisy_source_configs
|
function _daisy_source_configs
|
||||||
{
|
{
|
||||||
|
|
@ -95,123 +112,8 @@ fi
|
||||||
# FUNCTIONS and ALIASES #######################################################
|
# FUNCTIONS and ALIASES #######################################################
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# bak and unbak
|
# Undocumented but internally used
|
||||||
function bak
|
function daisy_wait_for_editor
|
||||||
{
|
|
||||||
# Input: <file>
|
|
||||||
target=$1
|
|
||||||
|
|
||||||
# Check if file exists
|
|
||||||
if ! test -f "$target";
|
|
||||||
then
|
|
||||||
echo "Path not found: \"$target\""
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Handle both cases
|
|
||||||
if [[ $unbak_mode -eq 1 ]];
|
|
||||||
then
|
|
||||||
cp -R "$target.bak" "$target"
|
|
||||||
rm -rf "$target.bak"
|
|
||||||
echo "Restored backup: $target <-- $target.bak"
|
|
||||||
else
|
|
||||||
cp -R "$target" "$target.bak"
|
|
||||||
echo "Backup made: $target --> $target.bak"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
alias unbak="unbak_mode=1 bak"
|
|
||||||
alias lsa="ls -a -l -h"
|
|
||||||
alias lsn="ls -a -l -tu -r -h"
|
|
||||||
alias lss="ls -a -l -S -r -h"
|
|
||||||
|
|
||||||
# Simple version of `cdf`
|
|
||||||
function cdf
|
|
||||||
{
|
|
||||||
if [[ $LD_HAS_fzf != 1 ]];
|
|
||||||
then
|
|
||||||
echo "This alias requires the utility 'fzf'. Please install it."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
cd $(dirname $(fzf))
|
|
||||||
}
|
|
||||||
|
|
||||||
function cdp
|
|
||||||
{
|
|
||||||
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
|
|
||||||
then
|
|
||||||
echo "This alias requires the utilities 'peco' and 'tree'. Please install them."
|
|
||||||
echo "Consider using 'cdf' instead."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
cd $(dirname $(tree -fia --noreport . | peco))
|
|
||||||
}
|
|
||||||
|
|
||||||
function editpeco
|
|
||||||
{
|
|
||||||
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
|
|
||||||
then
|
|
||||||
echo "This alias requires the utilities 'peco' and 'tree'. Please install them."
|
|
||||||
echo "Consider using 'cdf' instead."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
tree --noreport -fia . | peco --prompt "Press CTRL+C to quit - query:" --exec "xargs -o -I{} $EDITOR {}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# for convenience purposes
|
|
||||||
function editbin
|
|
||||||
{
|
|
||||||
editx $(which $1)
|
|
||||||
}
|
|
||||||
|
|
||||||
# sets a new editor based on commony available ones, and some visual ones
|
|
||||||
function ched
|
|
||||||
{
|
|
||||||
editors=("nano" "vim" "nvim" "vi" "emacs" "gedit" "kate" "mousepad" "micro" \
|
|
||||||
"code" "subl" "joe" "kwrite" "gnome-text-editor")
|
|
||||||
|
|
||||||
# Find which editors are installed
|
|
||||||
available_editors=()
|
|
||||||
for editor in "${editors[@]}";
|
|
||||||
do
|
|
||||||
editor_real=$(command -v "$editor")
|
|
||||||
if command -v "$editor_real" >/dev/null 2>&1;
|
|
||||||
then
|
|
||||||
if [[ $(realpath "$EDITOR") == "$editor_real" ]];
|
|
||||||
then
|
|
||||||
available_editors+=("$editor_real" "$editor (current choice)")
|
|
||||||
else
|
|
||||||
available_editors+=("$editor_real" "$editor")
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ! -z $@ ]];
|
|
||||||
then
|
|
||||||
text="$@"
|
|
||||||
dialog --msgbox "$text" 0 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Present all choices
|
|
||||||
choice=$(dialog --output-fd 1 --clear --title "Select Text Editor" \
|
|
||||||
--menu "Choose one of the installed text editors:" 15 50 6 \
|
|
||||||
"${available_editors[@]}")
|
|
||||||
dialog_ret=$?
|
|
||||||
|
|
||||||
if [ $dialog_ret -ne 0 ];
|
|
||||||
then
|
|
||||||
echo "No editor selected."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo export EDITOR=$choice > "$LD_EDITORFILE"
|
|
||||||
echo export LD_EDITOR=$choice >> "$LD_EDITORFILE"
|
|
||||||
echo export LD_OLD_EDITOR=$EDITOR >>"$LD_EDITORFILE"
|
|
||||||
|
|
||||||
_daisy_source_configs
|
|
||||||
}
|
|
||||||
|
|
||||||
function wait_for_editor
|
|
||||||
{
|
{
|
||||||
pname="$1"
|
pname="$1"
|
||||||
fname="$2"
|
fname="$2"
|
||||||
|
|
@ -230,32 +132,224 @@ function wait_for_editor
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Undocumented but internally used
|
||||||
|
function daisy_editor
|
||||||
|
{
|
||||||
|
editor=${LD_EDITOR:-$EDITOR};
|
||||||
|
ld_dbg echo Opening $editor to edit file: $1
|
||||||
|
$editor "$1"
|
||||||
|
daisy_wait_for_editor $editor "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# bak and unbak
|
||||||
|
function bak
|
||||||
|
{
|
||||||
|
# Input: <file>
|
||||||
|
target=$1
|
||||||
|
|
||||||
|
# Check if file exists
|
||||||
|
if ! test -f "$target";
|
||||||
|
then
|
||||||
|
echo "Path not found: \"$target\""
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Handle both cases
|
||||||
|
if [[ $unbak_mode == 1 ]];
|
||||||
|
then
|
||||||
|
cp -R "$target.bak" "$target"
|
||||||
|
rm -rf "$target.bak"
|
||||||
|
echo "Restored backup: $target <-- $target.bak"
|
||||||
|
else
|
||||||
|
cp -R "$target" "$target.bak"
|
||||||
|
echo "Backup made: $target --> $target.bak"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function unbak
|
||||||
|
{
|
||||||
|
unbak_mode=1 bak $@
|
||||||
|
}
|
||||||
|
|
||||||
|
function lsa
|
||||||
|
{
|
||||||
|
ls -a -l -h $@
|
||||||
|
}
|
||||||
|
|
||||||
|
function lsn
|
||||||
|
{
|
||||||
|
ls -a -l -tu -r -h $@
|
||||||
|
}
|
||||||
|
|
||||||
|
function lss
|
||||||
|
{
|
||||||
|
ls -a -l -S -r -h $@
|
||||||
|
}
|
||||||
|
|
||||||
|
# Simple version of `cdf`
|
||||||
|
function cdf
|
||||||
|
{
|
||||||
|
if [[ $LD_HAS_fzf != 1 ]];
|
||||||
|
then
|
||||||
|
echo "This function requires the utility 'fzf'. Please install it."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
cd "$(dirname "$(fzf)")"
|
||||||
|
}
|
||||||
|
|
||||||
|
function cdp
|
||||||
|
{
|
||||||
|
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
|
||||||
|
then
|
||||||
|
echo "This function requires the utilities 'peco' and 'tree'. Please install them."
|
||||||
|
echo "Consider using 'cdf' instead."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
cd $(dirname $(tree -fia --noreport . | peco))
|
||||||
|
}
|
||||||
|
|
||||||
|
function editpeco
|
||||||
|
{
|
||||||
|
if [[ $LD_HAS_peco != 1 || $LD_HAS_tree != 1 ]];
|
||||||
|
then
|
||||||
|
echo "This function requires the utilities 'peco' and 'tree'. Please install them."
|
||||||
|
echo "Consider using 'cdf' instead."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
tree --noreport -fia . | peco --prompt "Press CTRL+C to quit - query:" --exec "xargs -o -I{} $EDITOR {}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# for convenience purposes
|
||||||
|
function editbin
|
||||||
|
{
|
||||||
|
editx $(which $1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# sets a new editor based on commony available ones, and some visual ones
|
||||||
|
function ched
|
||||||
|
{
|
||||||
|
override=0
|
||||||
|
if [[ $1 == "-g" ]];
|
||||||
|
then
|
||||||
|
override=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $LD_HAS_dialog != 1 ]];
|
||||||
|
then
|
||||||
|
echo "This function requires the utility 'dialog'. Please install it."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
editors=("nano" "vim" "nvim" "vi" "emacs" "gedit" "kate" "mousepad" "micro" \
|
||||||
|
"code" "subl" "joe" "kwrite" "gnome-text-editor")
|
||||||
|
|
||||||
|
# Find which editors are installed
|
||||||
|
available_editors=()
|
||||||
|
for editor in "${editors[@]}";
|
||||||
|
do
|
||||||
|
editor_real=$(command -v "$editor")
|
||||||
|
if command -v "$editor_rmeal" >/dev/null 2>&1;
|
||||||
|
then
|
||||||
|
if [[ $(realpath "$EDITOR") == "$editor_real" ]];
|
||||||
|
then
|
||||||
|
available_editors+=("$editor_real" "$editor (current)")
|
||||||
|
elif [[ $LD_EDITOR == "$editor_real" ]];
|
||||||
|
then
|
||||||
|
available_editors+=("$editor_real" "$editor (LD choice)")
|
||||||
|
else
|
||||||
|
available_editors+=("$editor_real" "$editor")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $override == 0 ]] && [[ ! -z $@ ]];
|
||||||
|
then
|
||||||
|
text="$@"
|
||||||
|
dialog --msgbox "$text" 0 0
|
||||||
|
elif [[ $override == 1 ]];
|
||||||
|
then
|
||||||
|
text="You have passed '-g'. Your choice of dialog will override any other choice or setting of 'EDITOR'."
|
||||||
|
dialog --msgbox "$text" 0 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Present all choices
|
||||||
|
choice=$(dialog --output-fd 1 --clear --title "Select Text Editor" \
|
||||||
|
--menu "Choose one of the installed text editors:" 15 100 6 \
|
||||||
|
"${available_editors[@]}")
|
||||||
|
dialog_ret=$?
|
||||||
|
|
||||||
|
if [ $dialog_ret -ne 0 ];
|
||||||
|
then
|
||||||
|
dialog --msgbox "No editor selected. Variables will not be updated." 0 0
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ $override == 0 ]] && echo export EDITOR="${EDITOR:-$choice}" > "$LD_EDITORFILE"
|
||||||
|
[[ $override == 1 ]] && echo export EDITOR="$choice" > "$LD_EDITORFILE"
|
||||||
|
echo export LD_EDITOR="$choice" >> "$LD_EDITORFILE"
|
||||||
|
echo export LD_OLD_EDITOR="$EDITOR" >> "$LD_EDITORFILE"
|
||||||
|
|
||||||
|
source "$LD_EDITORFILE"
|
||||||
|
}
|
||||||
|
|
||||||
function daisy_reload
|
function daisy_reload
|
||||||
{
|
{
|
||||||
FROM_RC=0 source "$LD_SOURCE_FILE"
|
LD_INTERNAL=0 source "$LD_SOURCE_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function ldrc
|
function ldrc
|
||||||
{
|
{
|
||||||
$EDITOR "$LD_SOURCE_FILE"
|
daisy_editor "$LD_SOURCE_FILE"
|
||||||
FROM_RC=0 source "$LD_SOURCE_FILE"
|
LD_INTERNAL=0 source "$LD_SOURCE_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enc_is_folder=0
|
||||||
function daisy_enc
|
function daisy_enc
|
||||||
{
|
{
|
||||||
if [ -d $1 ];
|
if [ -t 0 ] && [ -z "$1" ];
|
||||||
|
then
|
||||||
|
echo "# $0: No arguments or stdin specified!"
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -t 0 ] && [ -z "$1" ];
|
||||||
|
then
|
||||||
|
echo "# $0: Please provide a filename as argument when using stdin"
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$1" ] && [ -d "$1" ];
|
||||||
then
|
then
|
||||||
echo -e "daisy_create_folder=$1"
|
echo -e "daisy_create_folder=$1"
|
||||||
else
|
else
|
||||||
file_info=$(file $1)
|
file_dir=""
|
||||||
file_dir=$(dirname $1)
|
file_name=""
|
||||||
file_name=$(basename $1)
|
perms=755
|
||||||
|
|
||||||
|
target=$1
|
||||||
|
|
||||||
|
# [TODO, FIX: An unknown bug is causing daisy_enc_folder to misbehave if stdin is accessed, so we disable it here.]
|
||||||
|
if [[ ! -t 0 ]] && [[ $enc_is_folder == 0 ]];
|
||||||
|
then
|
||||||
|
file_dir="."
|
||||||
|
file_name="$1"
|
||||||
|
shift
|
||||||
|
elif [ -f "$1" ];
|
||||||
|
then
|
||||||
|
file_dir=$(dirname "$1")
|
||||||
|
file_name=$(basename "$1")
|
||||||
|
perms=$(stat -c %a "$1")
|
||||||
|
else
|
||||||
|
echo "# $0: An error occured during encoding."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
base64_inner=$(cat ${1:-/dev/stdin} | base64 | tr -d '\n')
|
base64_inner=$(cat ${1:-/dev/stdin} | base64 | tr -d '\n')
|
||||||
|
|
||||||
# Print out our block
|
# Print out our block
|
||||||
echo -e "daisy_folder_$file_name=$file_dir"
|
echo -e "daisy_folder_$file_name=$file_dir"
|
||||||
echo -e "daisy_data_base64_$file_name=\"$base64_inner\""
|
echo -e "daisy_data_base64_$file_name=\"$base64_inner\""
|
||||||
|
echo -e "daisy_perms_$file_name=$perms"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,13 +373,21 @@ function daisy_enc_folder
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
tree -fia --noreport . | sed 1d | while read -r item;
|
tree -fia --noreport . | sed 1d | while read -r item;
|
||||||
do
|
do
|
||||||
|
enc_is_folder=1
|
||||||
daisy_enc "$item"
|
daisy_enc "$item"
|
||||||
|
enc_is_folder=0
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function daisy_dec
|
function daisy_dec
|
||||||
{
|
{
|
||||||
|
if [ -t 0 ] && [ -z "$1" ];
|
||||||
|
then
|
||||||
|
echo "$0: No arguments or stdin specified!"
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
|
||||||
data=$(cat ${1:-/dev/stdin} | grep -v "#" )
|
data=$(cat ${1:-/dev/stdin} | grep -v "#" )
|
||||||
echo -e "$data" | cut -d "=" -f 2- | cut -b 2- | head -c -2 | base64 -d
|
echo -e "$data" | cut -d "=" -f 2- | cut -b 2- | head -c -2 | base64 -d
|
||||||
}
|
}
|
||||||
|
|
@ -294,15 +396,26 @@ function daisy_dec
|
||||||
# Extracts to the directory
|
# Extracts to the directory
|
||||||
function daisy_dec_multi
|
function daisy_dec_multi
|
||||||
{
|
{
|
||||||
[[ ! -f $1 ]] && echo "daisy_dec_multi: No input file specified" && return
|
arg1=$1
|
||||||
[[ ! -d $2 ]] && echo "daisy_dec_multi: No output directory specified" && return
|
arg2=$2
|
||||||
|
|
||||||
|
# Handle stdin support
|
||||||
|
if [ ! -t 0 ];
|
||||||
|
then
|
||||||
|
arg2=$1
|
||||||
|
arg1=/dev/stdin
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -t 0 ]] && [[ ! -f $arg1 ]] && echo "daisy_dec_multi: No input file specified" && return
|
||||||
|
[[ ! -d $arg2 ]] && echo "daisy_dec_multi: No output directory specified" && return
|
||||||
|
|
||||||
folder=
|
folder=
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
if [[ "$line" == "daisy_create_folder="* ]];
|
if [[ "$line" == "daisy_create_folder="* ]];
|
||||||
then
|
then
|
||||||
folder=$(echo $line | cut -d "=" -f 2)
|
folder=$(echo $line | cut -d "=" -f 2)
|
||||||
mkdir -p "$2/$folder"
|
echo $folder
|
||||||
|
mkdir -p "$arg2/$folder"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$line" == "daisy_folder"* ]];
|
if [[ "$line" == "daisy_folder"* ]];
|
||||||
|
|
@ -314,10 +427,17 @@ while IFS= read -r line; do
|
||||||
if [[ "$line" == "daisy_data_base64"* ]];
|
if [[ "$line" == "daisy_data_base64"* ]];
|
||||||
then
|
then
|
||||||
file=$(echo -e $line | cut -d "_" -f 4- | cut -d "=" -f 1)
|
file=$(echo -e $line | cut -d "_" -f 4- | cut -d "=" -f 1)
|
||||||
daisy_dec <(echo $line) > "$2/$folder/$file"
|
mkdir -p "$arg2/$folder"
|
||||||
|
daisy_dec <(echo $line) > "$arg2/$folder/$file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done <<< $(cat "$1")
|
if [[ "$line" == "daisy_perms"* ]];
|
||||||
|
then
|
||||||
|
file=$(echo -e $line | cut -d "_" -f 3- | cut -d "=" -f 1)
|
||||||
|
perms=$(echo -e $line | cut -d "_" -f 3- | cut -d "=" -f 2)
|
||||||
|
chmod $perms "$arg2/$folder/$file"
|
||||||
|
fi
|
||||||
|
done <<< $(cat "$arg1")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Saves a bit on typing
|
# Saves a bit on typing
|
||||||
|
|
@ -327,6 +447,24 @@ function grab
|
||||||
awk '{print $'$1'}'
|
awk '{print $'$1'}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clip
|
||||||
|
{
|
||||||
|
data=""
|
||||||
|
|
||||||
|
if [ ! -t 0 ]; then
|
||||||
|
data="$(cat)"
|
||||||
|
elif [ "$*" != "" ]; then
|
||||||
|
data="$*"
|
||||||
|
else
|
||||||
|
echo $LD_CLIP
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Export the variable
|
||||||
|
export LD_CLIP="$data"
|
||||||
|
echo "Variable set to \"$LD_CLIP\"."
|
||||||
|
}
|
||||||
|
|
||||||
function daisy_unalias
|
function daisy_unalias
|
||||||
{
|
{
|
||||||
unalias_param=$@
|
unalias_param=$@
|
||||||
|
|
@ -378,6 +516,60 @@ function daisy_alias
|
||||||
source $LD_ALIASFILE
|
source $LD_ALIASFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function daisy_backup
|
||||||
|
{
|
||||||
|
for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`;
|
||||||
|
do
|
||||||
|
bak "$f"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function daisy_clear
|
||||||
|
{
|
||||||
|
daisy_backup
|
||||||
|
|
||||||
|
for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`;
|
||||||
|
do
|
||||||
|
echo "Removing config file: $f"
|
||||||
|
rm -rf "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Config cleared. Use 'daisy_restore' if you would like to undo this."
|
||||||
|
daisy_reload
|
||||||
|
}
|
||||||
|
|
||||||
|
function daisy_restore
|
||||||
|
{
|
||||||
|
for f in `find "$LD_CONFIG_FOLDER" -name "*.src" -type f`;
|
||||||
|
do
|
||||||
|
unbak "$f"
|
||||||
|
bak "$f" 1>/dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Config restored. Backups have been retained."
|
||||||
|
daisy_reload
|
||||||
|
}
|
||||||
|
|
||||||
|
# Aliases for front-facing daisy_ functions
|
||||||
|
function _daisy_def_alias
|
||||||
|
{
|
||||||
|
alias ld_$1=daisy_$1
|
||||||
|
}
|
||||||
|
|
||||||
|
_daisy_def_alias reload
|
||||||
|
_daisy_def_alias enc
|
||||||
|
_daisy_def_alias enc_multi
|
||||||
|
_daisy_def_alias enc_folder
|
||||||
|
_daisy_def_alias dec
|
||||||
|
_daisy_def_alias dec_multi
|
||||||
|
_daisy_def_alias alias
|
||||||
|
_daisy_def_alias unalias
|
||||||
|
_daisy_def_alias backup
|
||||||
|
_daisy_def_alias clear
|
||||||
|
_daisy_def_alias restore
|
||||||
|
_daisy_def_alias help
|
||||||
|
_daisy_def_alias list
|
||||||
|
|
||||||
_daisy_source_configs
|
_daisy_source_configs
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
@ -387,32 +579,11 @@ _daisy_source_configs
|
||||||
# End of user section!
|
# End of user section!
|
||||||
export LD_AVAILABLE=1
|
export LD_AVAILABLE=1
|
||||||
|
|
||||||
# Start of internal section
|
|
||||||
function daisy_quit_if_no
|
|
||||||
{
|
|
||||||
local dep_name="daisy_has_$1"
|
|
||||||
local has_dep="${!dep_name}"
|
|
||||||
|
|
||||||
# Check first if we have checked for this dependency, if not, print a fixme!
|
|
||||||
# TODO: Remove upon release, or convert into self-modifying code.
|
|
||||||
if [[ -z "$has_dep" ]];
|
|
||||||
then
|
|
||||||
echo "FIXME: Dependency `$1` should have an env variable, checking ad-hoc"
|
|
||||||
has_dep=$(daisy_dependency_check $1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $has_dep -eq 0 ]];
|
|
||||||
then
|
|
||||||
echo "$LD_BIN: The dependency $1 was not found! Please install it" \
|
|
||||||
"to be able to use this utility!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -d "$LD_FOLDER" ] && export LD_AVAILABLE=1
|
[ -d "$LD_FOLDER" ] && export LD_AVAILABLE=1
|
||||||
|
|
||||||
# Help function, courtesy of Google Gemini
|
# Help function, courtesy of Google Gemini
|
||||||
function daisy_help() {
|
function daisy_help()
|
||||||
|
{
|
||||||
local target_tool="$1"
|
local target_tool="$1"
|
||||||
local file="$LD_FOLDER/README.md"
|
local file="$LD_FOLDER/README.md"
|
||||||
|
|
||||||
|
|
@ -473,7 +644,8 @@ function daisy_help() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Courtesy of Google Gemini
|
# Courtesy of Google Gemini
|
||||||
daisy_list() {
|
daisy_list()
|
||||||
|
{
|
||||||
local file="$LD_FOLDER/README.md"
|
local file="$LD_FOLDER/README.md"
|
||||||
echo "Available LACKADAISICAL commands:"
|
echo "Available LACKADAISICAL commands:"
|
||||||
|
|
||||||
|
|
@ -489,16 +661,3 @@ daisy_list() {
|
||||||
}
|
}
|
||||||
' | sort
|
' | sort
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hide what we don't need
|
|
||||||
if [[ ! -v LD_INTERNAL ]];
|
|
||||||
then
|
|
||||||
unset -f _daisy_source_configs
|
|
||||||
unset -f wait_for_editor
|
|
||||||
unset -f daisy_quit_if_no
|
|
||||||
unset -f daisy_dependency_check
|
|
||||||
unset LD_HAS_fzf
|
|
||||||
unset LD_HAS_peco
|
|
||||||
unset LD_HAS_md5sum
|
|
||||||
unset LD_HAS_tree
|
|
||||||
fi
|
|
||||||
|
|
|
||||||
2
editx
2
editx
|
|
@ -1,4 +1,4 @@
|
||||||
# !/bin/bash
|
#!/usr/bin/env bash
|
||||||
# This utility pre-allocs a file and adds execution permissions. It also
|
# This utility pre-allocs a file and adds execution permissions. It also
|
||||||
# removes the resulting file if it is empty after the editor closes.
|
# removes the resulting file if it is empty after the editor closes.
|
||||||
|
|
||||||
|
|
|
||||||
2
filewait
2
filewait
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# A simple utility that waits for a file to become available, infinitely
|
# A simple utility that waits for a file to become available, infinitely
|
||||||
|
|
||||||
LD_INTERNAL=1
|
LD_INTERNAL=1
|
||||||
|
|
|
||||||
2
own
2
own
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Simple program that changes ownership to the current
|
# Simple program that changes ownership to the current
|
||||||
# user, recursively.
|
# user, recursively.
|
||||||
|
|
||||||
|
|
|
||||||
32
shrc
32
shrc
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/echo Please run this program with: ". shrc" or include
|
#!/usr/bin/env -S echo Please run this program with: ". shrc" or include
|
||||||
# `FROM_RC=1 source shrc` in your RC file to set up an alias.
|
# `FROM_RC=1 source shrc` in your RC file to set up an alias.
|
||||||
|
|
||||||
# Just opens your .rc file easily, for your current shell
|
# Just opens your .rc file easily, for your current shell
|
||||||
|
|
@ -10,37 +10,9 @@ then
|
||||||
LD_INTERNAL=1 source $LD_SOURCE_FILE
|
LD_INTERNAL=1 source $LD_SOURCE_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function md5_opt()
|
|
||||||
{
|
|
||||||
if [[ $daisy_has_md5sum -eq 1 ]];
|
|
||||||
then
|
|
||||||
echo $(md5sum "$1" | awk '{print $1}')
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $FROM_RC -eq 1 ]]; then
|
|
||||||
alias shrc=". shrc"
|
|
||||||
else
|
|
||||||
shellname=$(basename $SHELL)
|
shellname=$(basename $SHELL)
|
||||||
rc_name="."$shellname"rc"
|
rc_name="."$shellname"rc"
|
||||||
rc_path="$HOME/$rc_name"
|
rc_path="$HOME/$rc_name"
|
||||||
|
|
||||||
# Optional MD5 checks
|
daisy_editor "$rc_path"
|
||||||
has_changed=1
|
|
||||||
sum1=$(md5_opt "$rc_path")
|
|
||||||
|
|
||||||
# This sets a default if the variable does not exist.
|
|
||||||
EDITOR=${EDITOR:-$(ched)}
|
|
||||||
$EDITOR "$rc_path"
|
|
||||||
wait_for_editor $EDITOR "$rc_path"
|
|
||||||
|
|
||||||
sum2=$(md5_opt "$rc_path")
|
|
||||||
|
|
||||||
if [[ $daisy_has_md5sum -eq 1 && "$sum1" == "$sum2" ]];
|
|
||||||
then
|
|
||||||
echo "The RC-file $rc_name has not changed on disk. Not sourcing."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
source "$rc_path"
|
source "$rc_path"
|
||||||
fi
|
|
||||||
|
|
|
||||||
2
sshp
2
sshp
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
mounts=()
|
mounts=()
|
||||||
ssh_args=()
|
ssh_args=()
|
||||||
|
|
|
||||||
4
sw
4
sw
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# It just swaps two files
|
# It just swaps two files
|
||||||
|
|
||||||
export LD_INTERNAL1
|
LD_INTERNAL1
|
||||||
. $(dirname $(realpath $0))/daisy.source
|
. $(dirname $(realpath $0))/daisy.source
|
||||||
|
|
||||||
file1=$1
|
file1=$1
|
||||||
|
|
|
||||||
2
what
2
what
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Where is the binary?
|
# Where is the binary?
|
||||||
# Usage: what [<keyword>]
|
# Usage: what [<keyword>]
|
||||||
# Returns:
|
# Returns:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue