-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_tdir
More file actions
executable file
·24 lines (20 loc) · 737 Bytes
/
Copy path_tdir
File metadata and controls
executable file
·24 lines (20 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
__track_usage "$(basename "$0")"
# Temp dir with historic log file to easily traverse with _ptdir
# Used w/ corresponding zsh function tdir to actually do the directory switching in parent shell
TMP_FILE_TEMPLATE=""
if is_os_linux ; then
TMP_FILE_TEMPLATE="nj.XXX"
elif is_os_osx ; then
TMP_FILE_TEMPLATE="nj"
else
print_error "Unknown operating system"
exit 1
fi
log_file="$HOME/.tdir";
_date=$(date "+%Y_%m_%d__%H_%M_%S_%p");
_context=$(pwd)
_dir=$(mktemp -d -t "$TMP_FILE_TEMPLATE") \
&& echo -e "$_date\t$_dir\t$_context" >> "$log_file" \
&& echo "$_dir" \
|| { print_error "Failed to create temp dir, staying in cur dir."; echo "$PWD"; exit 1; } # echo PWD because the wrapper to this is `cd $(_ptdr)`