@@ -27,7 +27,7 @@ var UseAuthCanI bool = true
27
27
// Main starts Peirates[]
28
28
func Main () {
29
29
// Peirates version string
30
- var version = "1.1.22 "
30
+ var version = "1.1.23 "
31
31
32
32
var err error
33
33
@@ -227,6 +227,101 @@ func Main() {
227
227
continue
228
228
}
229
229
230
+ //
231
+ // Handle built-in filesystem commands before the switch menu
232
+ //
233
+
234
+ const pwd = "pwd"
235
+ if input == pwd {
236
+ // Print the current working directory
237
+ cwd , error := getCurrentDirectory ()
238
+ if error != nil {
239
+ println ("Error getting current directory: " + error .Error ())
240
+ continue
241
+ }
242
+ println (cwd )
243
+ pauseToHitEnter (interactive )
244
+ continue
245
+ }
246
+
247
+ const cdSpace = "cd "
248
+ if strings .HasPrefix (input , cdSpace ) {
249
+
250
+ // Trim off the newline - should we do this for all input anyway?
251
+ input = strings .TrimSuffix (input , "\n " )
252
+ // Trim off the cd, then grab the argument.
253
+ // This will fail if there are spaces in the directory name - TODO: improve this.
254
+ argumentsLine := strings .TrimPrefix (input , cdSpace )
255
+ arguments := strings .Fields (argumentsLine )
256
+ directory := arguments [0 ]
257
+ // remove the cd, then try to change to that directory
258
+ changeDirectory (directory )
259
+
260
+ // Get the new directory and print its name
261
+ cwd , error := getCurrentDirectory ()
262
+ if error != nil {
263
+ println ("Error getting current directory: " + error .Error ())
264
+ continue
265
+ }
266
+ println (cwd )
267
+
268
+ pauseToHitEnter (interactive )
269
+ continue
270
+ }
271
+
272
+ // cat to display files
273
+ const catSpace = "cat "
274
+ if strings .HasPrefix (input , catSpace ) {
275
+ // Trim off the newline - should we do this for all input anyway?
276
+ input = strings .TrimSuffix (input , "\n " )
277
+ // remove the cat, then split the rest on whitespace
278
+ argumentsLine := strings .TrimPrefix (input , catSpace )
279
+ spaceDelimitedSet := strings .Fields (argumentsLine )
280
+ for _ , file := range spaceDelimitedSet {
281
+ err := displayFile (file )
282
+ if err != nil {
283
+ println ("Error displaying file: " + file + " due to " + err .Error ())
284
+ }
285
+ }
286
+ pauseToHitEnter (interactive )
287
+ continue
288
+ }
289
+
290
+ // ls to list directories - treat this differently if it has no arguments
291
+
292
+ const lsSpace = "ls "
293
+ if strings .HasPrefix (input , lsSpace ) {
294
+ // Trim off the newline - should we do this for all input anyway?
295
+ input = strings .TrimSuffix (input , "\n " )
296
+ // remove the ls, then split the rest on whitespace
297
+ argumentsLine := strings .TrimPrefix (input , lsSpace )
298
+ spaceDelimitedSet := strings .Fields (argumentsLine )
299
+ for _ , dir := range spaceDelimitedSet {
300
+ // Check for flags - reject them
301
+ if strings .HasPrefix (dir , "-" ) {
302
+ println ("ERROR: Flags are not supported in this version of ls." )
303
+ continue
304
+ }
305
+ err := listDirectory (dir )
306
+ if err != nil {
307
+ println ("Error listing directory: " + dir + " due to " + err .Error ())
308
+ }
309
+ }
310
+ pauseToHitEnter (interactive )
311
+ continue
312
+ }
313
+
314
+ // ls with no arguments means list the current directory
315
+ const ls = "ls"
316
+ if strings .HasPrefix (input , ls ) {
317
+ error := listDirectory ("." )
318
+ if error != nil {
319
+ println ("Error listing directory: " + error .Error ())
320
+ }
321
+ pauseToHitEnter (interactive )
322
+ continue
323
+ }
324
+
230
325
// Handle shell commands before the switch menu
231
326
const shellSpace = "shell "
232
327
const shell = "shell"
0 commit comments