2019-01-12 15:47:23 +00:00
|
|
|
###########################
|
2020-02-02 15:08:42 +00:00
|
|
|
# Settings
|
2019-01-12 15:47:23 +00:00
|
|
|
|
|
|
|
# These can be overwritten any time.
|
|
|
|
# If they are not set yet, they will be
|
|
|
|
# overwritten with their default values
|
|
|
|
|
2020-06-11 14:59:30 +00:00
|
|
|
default fastfile_dir "${HOME}/.fastfile/"
|
2019-01-12 15:47:23 +00:00
|
|
|
default fastfile_var_prefix "§"
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Impl
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate a shortcut
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1. name - The name of the shortcut (default: name of the file)
|
|
|
|
# 2. file - The file or directory to make the shortcut for
|
|
|
|
# STDOUT:
|
|
|
|
# => fastfle_print
|
|
|
|
#
|
|
|
|
function fastfile() {
|
|
|
|
test "$2" || 2="."
|
|
|
|
file=$(readlink -f "$2")
|
2020-02-02 15:08:42 +00:00
|
|
|
|
2019-01-12 15:47:23 +00:00
|
|
|
test "$1" || 1="$(basename "$file")"
|
|
|
|
name=$(echo "$1" | tr " " "_")
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p "${fastfile_dir}"
|
|
|
|
echo "$file" > "$(fastfile_resolv "$name")"
|
|
|
|
|
|
|
|
fastfile_sync
|
|
|
|
fastfile_print "$name"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Resolve the location of a shortcut file (the database file, where the value is written!)
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1. name - The name of the shortcut
|
|
|
|
# STDOUT:
|
2020-02-02 15:08:42 +00:00
|
|
|
# The path to the shortcut file
|
2019-01-12 15:47:23 +00:00
|
|
|
#
|
|
|
|
function fastfile_resolv() {
|
|
|
|
echo "${fastfile_dir}${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get the real path of a shortcut
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1. name - The name of the shortcut
|
|
|
|
# STDOUT:
|
|
|
|
# The path
|
|
|
|
#
|
|
|
|
function fastfile_get() {
|
|
|
|
cat "$(fastfile_resolv "$1")"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Print a shortcut
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1. name - The name of the shortcut
|
|
|
|
# STDOUT:
|
|
|
|
# Name and value of the shortcut
|
|
|
|
#
|
|
|
|
function fastfile_print() {
|
|
|
|
echo "${fastfile_var_prefix}${1} -> $(fastfile_get "$1")"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# List all shortcuts
|
|
|
|
#
|
|
|
|
# STDOUT:
|
|
|
|
# (=> fastfle_print) for each shortcut
|
|
|
|
#
|
|
|
|
function fastfile_ls() {
|
2020-06-11 14:59:30 +00:00
|
|
|
for f in "${fastfile_dir}"/*; do
|
2020-02-02 15:08:42 +00:00
|
|
|
file=`basename "$f"` # To enable simpler handeling of spaces in file names
|
|
|
|
varkey=`echo "$file" | tr " " "_"`
|
2019-01-12 15:47:23 +00:00
|
|
|
|
2020-02-02 15:08:42 +00:00
|
|
|
# Special format for colums
|
|
|
|
echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
|
2019-01-12 15:47:23 +00:00
|
|
|
done | column -t -s "|"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Remove a shortcut
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1. name - The name of the shortcut (default: name of the file)
|
|
|
|
# STDOUT:
|
|
|
|
# => fastfle_print
|
|
|
|
#
|
|
|
|
function fastfile_rm() {
|
|
|
|
fastfile_print "$1"
|
|
|
|
rm "$(fastfile_resolv "$1")"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate the aliases for the shortcuts
|
|
|
|
#
|
|
|
|
function fastfile_sync() {
|
2020-06-11 14:59:30 +00:00
|
|
|
for f in "${fastfile_dir}"/*; do
|
2020-02-02 15:08:42 +00:00
|
|
|
file=`basename "$f"` # To enable simpler handeling of spaces in file names
|
|
|
|
varkey=`echo "$file" | tr " " "_"`
|
2019-01-12 15:47:23 +00:00
|
|
|
|
2020-02-02 15:08:42 +00:00
|
|
|
alias -g "${fastfile_var_prefix}${varkey}"="'$(fastfile_get "$file")'"
|
2019-01-12 15:47:23 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Shortcuts
|
|
|
|
|
|
|
|
alias ff=fastfile
|
|
|
|
alias ffp=fastfile_print
|
|
|
|
alias ffrm=fastfile_rm
|
|
|
|
alias ffls=fastfile_ls
|
|
|
|
alias ffsync=fastfile_sync
|
|
|
|
|
|
|
|
##################################
|
2020-02-02 15:08:42 +00:00
|
|
|
# Init
|
2019-01-12 15:47:23 +00:00
|
|
|
|
2020-02-02 15:08:42 +00:00
|
|
|
fastfile_sync
|