1 ###########################
4 # These can be overwritten any time.
5 # If they are not set yet, they will be
6 # overwritten with their default values
8 default fastfile_dir "${HOME}/.fastfile"
9 default fastfile_var_prefix "ยง"
11 ###########################
18 # 1. name - The name of the shortcut (default: name of the file)
19 # 2. file - The file or directory to make the shortcut for
25 file=$(readlink -f "$2")
27 test "$1" || 1="$(basename "$file")"
28 name=$(echo "$1" | tr " " "_")
31 mkdir -p "${fastfile_dir}"
32 echo "$file" > "$(fastfile_resolv "$name")"
35 fastfile_print "$name"
39 # Resolve the location of a shortcut file (the database file, where the value is written!)
42 # 1. name - The name of the shortcut
44 # The path to the shortcut file
46 function fastfile_resolv() {
47 echo "${fastfile_dir}/${1}"
51 # Get the real path of a shortcut
54 # 1. name - The name of the shortcut
58 function fastfile_get() {
59 cat "$(fastfile_resolv "$1")"
66 # 1. name - The name of the shortcut
68 # Name and value of the shortcut
70 function fastfile_print() {
71 echo "${fastfile_var_prefix}${1} -> $(fastfile_get "$1")"
78 # (=> fastfile_print) for each shortcut
80 function fastfile_ls() {
81 for f in "${fastfile_dir}"/*(N); do
82 file=$(basename "$f") # To enable simpler handling of spaces in file names
83 varkey=$(echo "$file" | tr " " "_")
85 # Special format for columns
86 echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
87 done | column -t -s "|"
94 # 1. name - The name of the shortcut (default: name of the file)
98 function fastfile_rm() {
100 rm "$(fastfile_resolv "$1")"
101 unalias "${fastfile_var_prefix}${1}"
105 # Generate the aliases for the shortcuts
107 function fastfile_sync() {
108 for f in "${fastfile_dir}"/*(N); do
109 file=$(basename "$f") # To enable simpler handling of spaces in file names
110 varkey=$(echo "$file" | tr " " "_")
112 alias -g "${fastfile_var_prefix}${varkey}"="'$(fastfile_get "$file")'"
116 ##################################
120 alias ffp=fastfile_print
121 alias ffrm=fastfile_rm
122 alias ffls=fastfile_ls
123 alias ffsync=fastfile_sync
125 ##################################