Skip to content

Instantly share code, notes, and snippets.

@victorMoneratto
Last active November 7, 2016 20:40
Show Gist options
  • Select an option

  • Save victorMoneratto/9b07a9a6f4845a2914d3bf9789f8a0cd to your computer and use it in GitHub Desktop.

Select an option

Save victorMoneratto/9b07a9a6f4845a2914d3bf9789f8a0cd to your computer and use it in GitHub Desktop.
My ZIM custom functions
mkdir -p $1
cd $1
local TO_TRASH="$(pwd)"
cd ..
trash "$TO_TRASH"
local EXPRESSION="$1"
if [ -z "$EXPRESSION" ]; then
echo "A folder expression must be provided." >&2
return 1
fi
if [ "$EXPRESSION" = "/" ]; then
cd "/"
return 0
fi
local CURRENT_FOLDER="$(pwd)"
local MATCHED_DIR=""
local MATCHING=true
while [ "$MATCHING" = true ]; do
if [[ "$CURRENT_FOLDER" =~ "$EXPRESSION" ]]; then
MATCHED_DIR="$CURRENT_FOLDER"
CURRENT_FOLDER=$(dirname "$CURRENT_FOLDER")
else
MATCHING=false
fi
done
if [ -n "$MATCHED_DIR" ]; then
cd "$MATCHED_DIR"
return 0
else
echo "No Match." >&2
return 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment