-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_1.sh
executable file
·189 lines (156 loc) · 4.38 KB
/
menu_1.sh
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# A sub-menu for main_menu script.
# ----------------------------------
# Step #1: Define variables
# ----------------------------------
RED='\033[0;41;30m'
STD='\033[0;0;39m'
# ----------------------------------
# Step #1: User defined function
# ----------------------------------
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
one(){
# --------------------------------------------------------------------------------------------------------
#OPEN FILES
# AS LONG AS THE USER TYPES THE FILE WITH THE EXTENSION, THE FILE SHOULD OPEN WITH THE DEFAULT APPLICATION
# --------------------------------------------------------------------------------------------------------
clear
dirrr="/home/mickey/Documents/bash/A/" # THIS IS NOT THE FINAL PATH
echo "Choose a File to open"
cd "/home/mickey/Documents/bash/A/"
echo "Please enter the file to open foolowed by the extension"
echo ""
ls
read openFile
if [ -f $openFile ]; then # -d means true if the file exists and is a directory
echo ""
echo "That file is there and a directory"
pause
xdg-open 2>/dev/null>/dev/null "$openFile"
clear
echo "File has been successfully opened"
pause
else
echo "Not there or not a directory"
pause
fi
clear
# User chooses a file to open in gedit / file manager.
}
######### as above but with copy/move code
two(){
# --------------------------------------------------------------------------------------------------------
#COPY FILES
# --------------------------------------------------------------------------------------------------------
dirr="/home/mickey/Documents/bash/B/" # THIS IS NOT THE FINAL PATH
dirA="/home/mickey/Documents/bash/A/"
clear
echo "Choose a File to Copy/Move to Folder "B""
echo ""
cd "$dirA"
ls
echo "Please enter the file name:"
read userInput
cd "$dirA"
ls
clear
if [ -f $userInput ]; then # -d means true if the file exists and is a directory
echo "That file is there and is a directory"
pause
cp "$userInput" "$dirr"
ls
clear
echo "File has been successfully copied to folder B"
pause
clear
cd "$dirr"
echo "List of files in folder B"
ls
clear
xdg-open 2>/dev/null>/dev/null "$dirr" #dev null displays with no debug information
else
echo "Not there or not a directory"
fi
pause
}
three(){
# --------------------------------------------------------------------------------------------------------
#RENAME FILES
# -------------------------------------------------------------------------------------------------------
dirA="/home/mickey/Documents/bash/A/"
clear
echo "Choose a File to Rename"
pause
clear
cd "$dirA"
echo "Please enter the file name followed by the renamed file"
ls
read target
if mv $source $target # this file name as an argument and renames it
then
clear
echo "Your file has been renamed"
ls
xdg-open 2>/dev/null>/dev/null "$dirA"
else
echo "File can not be renamed"
fi
pause
}
#RENAME multiple files
four() {
clear
cd "/home/mickey/Documents/bash/jpg/"
for file in *.jpg; do
mv "$file" "`basename "$file" .jpg`.png"
done
ls
xdg-open 2>/dev/null>/dev/null "/home/mickey/Documents/bash/jpg/"
cd "/home/mickey/Documents/bash/"
pause
echo "File extensions have been sucessfully renamed to png"
pause
}
# function to display menus
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " FOLDER A - M E N U"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Open File"
echo "2. Copy/Move File"
echo "3. Rename File"
echo "4. Rename File extensions"
echo "5. Exit"
}
# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# invoke the two() when the user select 2 from the menu option.
# invoke the three() when the user select 2 from the menu option.
# Exit when user the user select 3 form the menu option.
read_options(){
local choice
read -p "Enter choice [ 1 - 5] " choice
case $choice in
1) one ;;
2) two ;;
3) three ;;
4) four ;;
5) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# Step #4: Main logic - infinite loop
# ------------------------------------
while true
do
show_menus
read_options
done