de35b551417f7cceb2fefedf8df37ac4176fa09b

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1136 from koraa/pull_req_fastfile

On-the-fly creation and usage for file/dir shortcuts

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/fastfile/fastfile.plugin.zsh b/plugins/fastfile/fastfile.plugin.zsh
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..775e9483e35c045b8cf6c6fbcefc042466d28feb
  4--- /dev/null
  5+++ b/plugins/fastfile/fastfile.plugin.zsh
  6@@ -0,0 +1,138 @@
  7+################################################################################
  8+#          FILE:  fastfile.plugin.zsh
  9+#   DESCRIPTION:  oh-my-zsh plugin file.
 10+#        AUTHOR:  Michael Varner (musikmichael@web.de)
 11+#       VERSION:  1.0.0
 12+#
 13+# This plugin adds the ability to on the fly generate and access file shortcuts.
 14+#
 15+################################################################################
 16+
 17+###########################
 18+# Settings 
 19+
 20+# These can be overwritten any time.
 21+# If they are not set yet, they will be
 22+# overwritten with their default values
 23+
 24+default fastfile_dir        "${HOME}/.fastfile/"
 25+default fastfile_var_prefix "§"
 26+
 27+###########################
 28+# Impl
 29+
 30+#
 31+# Generate a shortcut
 32+#
 33+# Arguments:
 34+#    1. name - The name of the shortcut (default: name of the file)
 35+#    2. file - The file or directory to make the shortcut for
 36+# STDOUT:
 37+#    => fastfle_print
 38+#
 39+function fastfile() {
 40+    test "$2" || 2="."
 41+    file=$(readlink -f "$2")
 42+    
 43+    test "$1" || 1="$(basename "$file")"
 44+    name=$(echo "$1" | tr " " "_")
 45+
 46+
 47+    mkdir -p "${fastfile_dir}"
 48+    echo "$file" > "$(fastfile_resolv "$name")"
 49+
 50+    fastfile_sync
 51+    fastfile_print "$name"
 52+}
 53+
 54+#
 55+# Resolve the location of a shortcut file (the database file, where the value is written!)
 56+#
 57+# Arguments:
 58+#    1. name - The name of the shortcut
 59+# STDOUT:
 60+#   The path
 61+#
 62+function fastfile_resolv() {
 63+    echo "${fastfile_dir}${1}"
 64+}
 65+
 66+#
 67+# Get the real path of a shortcut
 68+#
 69+# Arguments:
 70+#    1. name - The name of the shortcut
 71+# STDOUT:
 72+#    The path
 73+#
 74+function fastfile_get() {
 75+    cat "$(fastfile_resolv "$1")"
 76+}
 77+
 78+#
 79+# Print a shortcut
 80+#
 81+# Arguments:
 82+#    1. name - The name of the shortcut
 83+# STDOUT:
 84+#    Name and value of the shortcut
 85+#
 86+function fastfile_print() {
 87+    echo "${fastfile_var_prefix}${1} -> $(fastfile_get "$1")"
 88+}
 89+
 90+#
 91+# List all shortcuts
 92+#
 93+# STDOUT:
 94+#    (=> fastfle_print) for each shortcut
 95+#
 96+function fastfile_ls() {
 97+    for f in "${fastfile_dir}"/*; do 
 98+	file=`basename "$f"` # To enable simpler handeling of spaces in file names
 99+	varkey=`echo "$file" | tr " " "_"`
100+
101+	# Special format for colums
102+	echo "${fastfile_var_prefix}${varkey}|->|$(fastfile_get "$file")"
103+    done | column -t -s "|"
104+}
105+