-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzotfile
executable file
·132 lines (109 loc) · 3.73 KB
/
zotfile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
VER='0.04'
#> This is work in progress any/all help appreciated
#---------------------------------------------------#
# Name: zotfile #
# #
# Purpose: Simple filesystem viewer #
# #
# Dependencies: gum #
# #
# Syntax: zotfile directory #
# #
# directory - where to start #
# default=$HOME #
# #
# Author/Contributors: #
# Lionel B. Dyck ([email protected]) #
# Igor Todorovski #
# #
# Change History (current on top): #
# 2024/02/14 LBD - 0.04 Improve messages #
# 2024/02/13 LBD - 0.03 Allow starting location #
# 2024/02/13 LBD - 0.02 Make it work (mostly) #
# 2024/02/13 LBD - 0.01 Creation #
#---------------------------------------------------#
# Repository: github.com/lbdyck/prompters #
#---------------------------------------------------#
# Copyleft by Lionel B. Dyck 2024 #
#---------------------------------------------------#
#----------------------------------------------------------------#
# Define the color for the banner #
# 5 - purple #
# 12 - blue shade #
# 33 - darker blue #
# 46 - green #
# 51 - turq shade #
#----------------------------------------------------------------#
COLOR=51
#----------------------------------------------------------------#
# Define export values that we need to look nice #
#----------------------------------------------------------------#
export GUM_INPUT_PROMPT_FOREGROUND="#$COLOR"
export GUM_INPUT_PLACEHOLDER=". . ."
export GUM_IMPORT_PROMPT="* "
export TERM=xterm-256color
#----------------------------------------------------------------#
# Define defaults #
#----------------------------------------------------------------#
EDITOR="vim"
VIEWER="gum pager"
if [ -z "$1" ]; then
DIR="$HOME"
else
DIR=$1
fi
doit()
{
banner
gum style \
--foreground $COLOR --border-foreground $COLOR \
'Navigate left: go up dir, right select dir, enter select file or q to exit.' \
'Scroll using up/down arrows.'
FP=$(gum file $DIR --height=20 --all --directory.foreground="$COLOR")
RC=$?
if [ "$RC" -eq 130 ] ; then
echo "Escape entered - exiting. . . "
exit 0
fi
DIR=$(dirname "$FP")
FILE=$(basename "$FP")
banner
OPT=$(gum choose 'Edit' 'View' --header.foreground="$COLOR" \
--header="File $FP selected. Select file processing option or Escape to cancel.")
RC=$?
if [ "$RC" -eq 130 ] ; then
doit
fi
case $OPT in
Edit )
cd $DIR
$EDITOR $FILE
doit
;;
View )
cd $DIR
cat $FILE | $VIEWER
doit
;;
esac
}
#----------------------#
# Display our banner #
#----------------------#
banner ()
{
clear
gum style \
--foreground $COLOR --border-foreground $COLOR --border double \
--align center --width 50 --margin "1 2" --padding "1 2" \
'z/OS Open Tools File Helper' $VER \
" " \
"Editor: $EDITOR" \
"Viewer: $VIEWER"
}
##Start of the working code
#-------------------#
# Now actually DoIt #
#-------------------#
doit