-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellshot.sh
More file actions
executable file
·50 lines (41 loc) · 1.31 KB
/
shellshot.sh
File metadata and controls
executable file
·50 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Fileshot
fileshot() {
local filename="$1"
shift
batcat --color=always --style=plain "$filename" --theme="Visual Studio Dark+" | pipeshot.py -t "$filename" "$@"
}
# Shellshot
record(){
if [[ -z $SHELLSHOT ]];then
dir="$HOME/.shellshot"
mkdir -p $dir
file="$dir/$(uuidgen)"
SHELLSHOT=$file exec script -qf $file
fi
}
if [[ -n $SHELLSHOT ]];then
# Unexport $SHELLSHOT to prevent children for inheriting
local file=$SHELLSHOT
unset SHELLSHOT
SHELLSHOT=$file
echo "recording..."
zshexit(){
rm $SHELLSHOT
}
# Path to save .svg and .png shellshots at:
: ${SHELLSHOT_EXPORT_DIR:="$(xdg-user-dir PICTURES)/shellshot"}
mkdir -p $SHELLSHOT_EXPORT_DIR
shot(){
local sanitize() { echo "${1:0:40}" | tr -dc '[:alnum:] -'; }
local BASE_FILENAME=$(sanitize "$(fc -lIn -1)") # to use the last ran command as filename
#local BASE_FILENAME="shellshot_$(date +"%Y-%m-%d %Hh%Mm%S")" # to use date as filename
local FILENAME="$BASE_FILENAME"
local i=1
while [[ -e "$SHELLSHOT_EXPORT_DIR/$FILENAME.png" || -e "$SHELLSHOT_EXPORT_DIR/$FILENAME.svg" ]]; do
FILENAME="${BASE_FILENAME}_$i"
((i++))
done
shellshot.py -o "$SHELLSHOT_EXPORT_DIR/$FILENAME" --open --clipboard "$SHELLSHOT" "$@"
}
fi
record # comment this line to disable automatic recording