summaryrefslogblamecommitdiffstats
path: root/2024/captions/emacsconf-2024-shell--emacs-as-a-shell--christopher-howard--main.vtt
blob: 7f16a859f95f1b7a3960134c7b64ce93abf9a9f4 (plain) (tree)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142





















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                   
WEBVTT captioned by mark

NOTE Introduction

00:00:02.940 --> 00:00:08.719
Welcome to Emacs as a Shell, a talk by Christopher Howard for

00:00:08.720 --> 00:00:13.799
Emacs Conference 2024.

00:00:13.800 --> 00:00:18.399
In this talk, I would like to explore, or advocate for, a

00:00:18.400 --> 00:00:21.919
particular perspective. I want to encourage people to

00:00:21.920 --> 00:00:26.479
think of Emacs not as simply an editor or a development

00:00:26.480 --> 00:00:31.119
environment, but rather as a shell, or at least something

00:00:31.120 --> 00:00:33.919
that allows us to do most of the things that we might

00:00:33.920 --> 00:00:37.880
otherwise want to do from a shell.

NOTE What do I mean by shell?

00:00:37.881 --> 00:00:40.839
What do I mean by shell? By

00:00:40.840 --> 00:00:45.439
shell, I mean basically an interface that allows us to

00:00:45.440 --> 00:00:50.679
interact with the rest of our system by entering commands.

00:00:50.680 --> 00:00:55.039
That definition is, perhaps, a little too broad, and so I

00:00:55.040 --> 00:00:58.439
will try to narrow it down with a list of features that,

00:00:58.440 --> 00:01:03.279
historically, we have come to expect from a shell. The Bash

00:01:03.280 --> 00:01:07.719
shell is one very portable and well-known shell, and for

00:01:07.720 --> 00:01:13.599
many of us it is maybe the prototypical example. But in the

00:01:13.600 --> 00:01:16.879
past there have been many other shells, and there are other

00:01:16.880 --> 00:01:21.119
shells available today. If we are willing to be flexible in

00:01:21.120 --> 00:01:25.559
our thinking, we can think of Emacs as being a shell, or at

00:01:25.560 --> 00:01:28.879
least providing most of the functionality that we expect

00:01:28.880 --> 00:01:38.559
from a shell.

NOTE What I do not mean

00:01:38.560 --> 00:01:42.759
Before further expanding on this idea, I must emphasize

00:01:42.760 --> 00:01:47.159
what I do not mean. First of all, I am not talking about

00:01:47.160 --> 00:01:51.439
running Bash, or some other external shell, from within

00:01:51.440 --> 00:01:56.439
Emacs, although this is certainly possible. I am arguing,

00:01:56.440 --> 00:02:02.439
rather, for using Emacs as a shell, instead of other shells.

00:02:02.440 --> 00:02:06.239
Second, I do not mean running a terminal emulator from

00:02:06.240 --> 00:02:11.399
within Emacs. Emacs has a built-in terminal emulator, but

00:02:11.400 --> 00:02:15.839
this is not what I mean. A terminal emulator is essentially a

00:02:15.840 --> 00:02:20.039
program designed to control the cursor and text appearance

00:02:20.040 --> 00:02:23.999
in response to various control codes in order to mimic a

00:02:24.000 --> 00:02:28.439
terminal display device. There are certainly legitimate

00:02:28.440 --> 00:02:32.559
reasons to do this. Nevertheless, in general, it does not

00:02:32.560 --> 00:02:36.519
make much sense to run a terminal emulator within Emacs,

00:02:36.520 --> 00:02:39.719
because Emacs has its own commands for controlling the

00:02:39.720 --> 00:02:45.039
cursor and text appearance. Also, due to the way Emacs was

00:02:45.040 --> 00:02:48.919
designed historically, Emacs itself believes that it is

00:02:48.920 --> 00:02:53.119
running on a terminal. So you end up with layers upon layers

00:02:53.120 --> 00:02:58.199
of terminal emulation. Anyhow, at the end of the day, Emacs

00:02:58.200 --> 00:03:01.839
will not perform as well as a dedicated terminal emulator

00:03:01.840 --> 00:03:08.079
program. I also think that, as we try to force ANSI terminal

00:03:08.080 --> 00:03:12.359
emulation into our Emacs workflow, this ultimately will be

00:03:12.360 --> 00:03:15.879
a hindrance to us in taking advantage of the natural and

00:03:15.880 --> 00:03:19.319
pleasant interfaces that are already available to us

00:03:19.320 --> 00:03:24.999
within Emacs. In brief, if your goal is simply to figure out

00:03:25.000 --> 00:03:28.499
how to be able to do all your normal Bash command line

00:03:28.500 --> 00:03:32.359
wizardry from within an Emacs window instead of a GNOME

00:03:32.360 --> 00:03:36.479
console window, you are headed down a different set of train

00:03:36.480 --> 00:03:43.199
tracks than I am. Also, something which I fear may confuse

00:03:43.200 --> 00:03:47.919
the issue for some viewers is the fact that Emacs ships with

00:03:47.920 --> 00:03:52.839
its own unique built-in shell, called the Emacs shell, or

00:03:52.840 --> 00:03:59.079
Eshell.

00:03:59.080 --> 00:04:02.959
Eshell aims to be a legitimate shell, and provides a very

00:04:02.960 --> 00:04:07.599
similar experience to other shells like Bash, while being

00:04:07.600 --> 00:04:11.119
well integrated into the Emacs interface, and without

00:04:11.120 --> 00:04:15.639
giving up the power of the Emacs Lisp engine. Eshell will be

00:04:15.640 --> 00:04:19.139
mentioned multiple times in this talk. The entire talk

00:04:19.140 --> 00:04:24.179
could, in fact, be about Eshell, except that I want the talk

00:04:24.180 --> 00:04:28.319
to cover all aspects of Emacs shell-like functionality

00:04:28.320 --> 00:04:32.079
through its other tools, such as interactive commands and

00:04:32.080 --> 00:04:37.079
special modes. So, hopefully we can keep distinct in our

00:04:37.080 --> 00:04:43.279
mind the ideas of Emacs as a shell versus the Emacs shell,

00:04:43.880 --> 00:04:50.159
though the latter is an important part of the former.

NOTE What is a shell?

00:04:50.160 --> 00:04:55.399
Let's get back to the fundamental idea of what is a shell. In

00:04:55.400 --> 00:04:59.159
the broadest definition, a shell is an interface which

00:04:59.160 --> 00:05:02.279
allows you to interact with your operating system through

00:05:02.280 --> 00:05:06.840
commands. However, from a historical perspective, there

00:05:06.841 --> 00:05:10.699
are a few basic capabilities which we expect to be part of

00:05:10.700 --> 00:05:17.880
every shell.

00:05:17.881 --> 00:05:21.420
First of all, the shell provides a means of launching

00:05:21.421 --> 00:05:26.440
external programs. Some internal or built-in commands

00:05:26.441 --> 00:05:31.679
might also be made available. Second, the shell provides a

00:05:31.680 --> 00:05:36.820
means of managing environment variables. In the past,

00:05:36.821 --> 00:05:40.580
environment variables often played a critical role as a

00:05:40.581 --> 00:05:45.360
means of passing in options, file names, device names, and

00:05:45.361 --> 00:05:50.119
suchlike to external programs. This is not quite as common

00:05:50.120 --> 00:05:54.080
today, but the environment still plays a critical role in

00:05:54.081 --> 00:05:57.619
managing things such as the path to executables and

00:05:57.620 --> 00:06:03.080
libraries, as well as various other user, desktop, and

00:06:03.081 --> 00:06:08.280
system settings. The shell modifies the environment and

00:06:08.281 --> 00:06:11.620
passes it on to external programs.

00:06:13.540 --> 00:06:17.580
Historically, job control was expected to be either a

00:06:17.581 --> 00:06:21.560
function of the shell, or easily accessible from it.

00:06:21.561 --> 00:06:24.019
Usually today, our personal computing is not

00:06:24.020 --> 00:06:29.280
batch-oriented. But typically, shells can run multiple

00:06:29.281 --> 00:06:34.599
processes simultaneously, as well as provide means to

00:06:34.600 --> 00:06:38.780
suspend and terminate processes, which are useful

00:06:38.781 --> 00:06:44.880
features. Shells should be able to redirect and pipeline

00:06:44.881 --> 00:06:49.100
process input and output. This allows the user to connect

00:06:49.101 --> 00:06:53.880
process input and output with files, devices, or other

00:06:53.881 --> 00:06:58.813
processes. Finally, shells are expected to have some

00:06:58.814 --> 00:07:02.380
limited scripting capability, such as the

00:07:02.381 --> 00:07:06.613
POSIX-compliant set of program statements and

00:07:06.614 --> 00:07:08.880
conditionals that Bash provides.

00:07:11.100 --> 00:07:15.113
As command-line wizards, there are a number of tasks we

00:07:15.114 --> 00:07:18.280
expect to be able to do quickly and easily from our shell,

00:07:18.660 --> 00:07:21.646
even though these tasks are not the domain of the shell

00:07:21.647 --> 00:07:27.880
itself. A common task is file management and navigation. We

00:07:27.881 --> 00:07:31.113
quickly navigate and manipulate the file system with

00:07:31.114 --> 00:07:34.813
standard utilities that do things like change the current

00:07:34.814 --> 00:07:39.380
working directory, rename files, move files, and delete

00:07:39.381 --> 00:07:44.146
files. We usually expect to have access to some additional

00:07:44.147 --> 00:07:48.380
process management utilities. These allow us to do things

00:07:48.381 --> 00:07:51.780
such as find out the status of all processes running on the

00:07:51.781 --> 00:07:57.980
system, and send signals to processes. Finally, we expect

00:07:57.981 --> 00:08:02.113
to have access to some basic networking utilities. For

00:08:02.114 --> 00:08:05.413
example, we should be able to run commands that set up

00:08:05.414 --> 00:08:09.513
network interfaces, ping computers, and download files.

00:08:09.514 --> 00:08:16.080
With a little reflection, we can see that Emacs can provide

00:08:16.081 --> 00:08:20.146
all or nearly all of the functionality we have described so

00:08:20.147 --> 00:08:24.046
far. And the functionality can be called conveniently

00:08:24.047 --> 00:08:26.746
through one of several methods.

00:08:33.520 --> 00:08:43.846
Either a normal interactive call, like M-x something, or a

00:08:43.847 --> 00:08:46.013
call to an elisp function,

00:08:53.620 --> 00:09:01.180
or through Eshell commands, or through some special buffer

00:09:01.181 --> 00:09:06.946
mode, such as the directory editor, which provides its own

00:09:06.947 --> 00:09:09.413
interface to some functionality.

00:09:09.414 --> 00:09:17.413
It may be going too far to say that Emacs is a full replacement

00:09:17.414 --> 00:09:21.713
for shells like Bash. Nevertheless, we can see that Emacs

00:09:21.714 --> 00:09:25.680
can do most of the things that we might otherwise do with our

00:09:25.681 --> 00:09:26.911
shell.

NOTE Launching external processes

00:09:26.912 --> 00:09:32.513
Let us give some examples. First, can Emacs launch

00:09:32.514 --> 00:09:36.680
external commands? Of course. Now, there are something

00:09:36.681 --> 00:09:40.446
like a half-dozen different ways to do that within Emacs, and

00:09:40.447 --> 00:09:46.713
some are more convenient than others. From any Elisp

00:09:46.714 --> 00:09:50.780
program, we can call functions like make-process and

00:09:50.781 --> 00:09:53.913
call-process to launch external processes.

00:10:12.460 --> 00:10:16.846
These, however, generally are not convenient for quick,

00:10:16.847 --> 00:10:22.380
one-off commands. Another option would be to run Eshell,

00:10:22.381 --> 00:10:26.580
which would allow us to call the external program from a

00:10:26.581 --> 00:10:28.946
familiar command line prompt.

00:10:34.160 --> 00:10:38.880
If we do not actually want to drop into Eshell just to run one

00:10:38.881 --> 00:10:42.213
command, we also have the interactive command,

00:10:42.214 --> 00:10:44.613
eshell-command,

00:10:52.420 --> 00:10:56.746
which would allow us to call the external program from a

00:10:56.747 --> 00:10:59.180
familiar command line prompt.

00:11:09.940 --> 00:11:12.080
If we do not actually want to drop an

00:11:12.081 --> 00:11:15.699
Eshell just to run one command, as I just mentioned, we also

00:11:15.700 --> 00:11:19.799
have the interactive command eshell-command, which allows

00:11:19.800 --> 00:11:23.399
us to enter in a one-off command and run that immediately.

00:11:25.420 --> 00:11:28.799
And finally, there is also an interactive command called

00:11:28.800 --> 00:11:30.499
simply shell-command.

00:11:34.600 --> 00:11:39.099
Shell command is like Eshell command, but instead passes

00:11:39.100 --> 00:11:42.899
the command off to our system shell, for example, bash.

00:11:43.940 --> 00:11:48.599
This is cheating, of course, but it might be useful or convenient

00:11:48.600 --> 00:11:57.299
in some scenarios.

NOTE Environment variables

00:11:57.300 --> 00:12:01.899
Regarding environment variables, Emacs can read and

00:12:01.900 --> 00:12:05.399
manipulate the environment variables, which in turn get

00:12:05.400 --> 00:12:09.659
passed on to processes which it launches. The

00:12:09.660 --> 00:12:12.899
general-purpose interactive commands for this are

00:12:12.900 --> 00:12:18.499
getenv and setenv. These commands

00:12:18.500 --> 00:12:21.799
deal with the one environment that is available throughout

00:12:21.800 --> 00:12:25.699
all parts of your running Emacs session. In other words,

00:12:25.700 --> 00:12:28.999
these functions deal with a global environment, which is

00:12:29.000 --> 00:12:32.099
the same wherever you are running getenv or

00:12:32.100 --> 00:12:34.399
setenv.

00:13:00.340 --> 00:13:04.259
An important exception is that every instance of Eshell

00:13:04.260 --> 00:13:07.599
maintains a distinct environment that will not be affected

00:13:07.600 --> 00:13:13.980
by setenv calls run in other buffers. Also, Eshell

00:13:13.981 --> 00:13:16.446
has some additional syntax for dealing with its

00:13:16.447 --> 00:13:20.780
environment, including the set and export syntax.

00:13:38.647 --> 00:13:47.113
Regarding job control and process management, Emacs does

00:13:47.114 --> 00:13:50.880
not provide job control in the way that Bash users are used

00:13:50.881 --> 00:13:57.080
to. We can, however, launch asynchronous processes, and do

00:13:57.081 --> 00:14:01.580
various things to them. From Eshell, or an eshell-command

00:14:01.581 --> 00:14:07.180
call, we can append the ampersand symbol to the command, and

00:14:07.181 --> 00:14:11.013
this will cause the process to run asynchronously in a

00:14:11.014 --> 00:14:13.313
dedicated buffer.

00:14:20.881 --> 00:14:25.280
Now, if the command is launched from Eshell, it will not

00:14:25.281 --> 00:14:31.180
actually run in a separate buffer, but the output will go to

00:14:31.181 --> 00:14:33.413
the Eshell buffer.

NOTE Processes

00:14:54.400 --> 00:14:59.580
We can run the interactive command list-processes to see

00:14:59.581 --> 00:15:02.846
all the processes running for our current Emacs session.

00:15:11.747 --> 00:15:17.646
In Eshell, we can run the command "jobs" to get the same list.

00:15:17.647 --> 00:15:22.813
This will show the process name, process buffer name,

00:15:22.814 --> 00:15:28.613
process ID, and some other information. We can select the

00:15:28.614 --> 00:15:32.880
process buffer in the process list to bring up that process

00:15:32.881 --> 00:15:36.213
buffer.

00:15:42.414 --> 00:15:47.046
We can also use the interactive command signal-process to

00:15:47.047 --> 00:15:52.980
send any signal to a process, including "stop" to suspend the

00:15:52.981 --> 00:15:58.380
process, "continue" to resume the process, and "interrupt" or

00:15:58.381 --> 00:16:02.546
kill to terminate the process.

NOTE Redirecting and pipelining input and output

00:17:00.180 --> 00:17:04.813
Regarding redirecting and pipelining input and output,

00:17:04.814 --> 00:17:11.613
Eshell does support redirection similar to Bash, so you can

00:17:11.614 --> 00:17:17.046
overwrite and append to files and some other objects. Input

00:17:17.047 --> 00:17:22.380
redirection is not yet implemented, but it is on the Eshell

00:17:22.381 --> 00:17:29.213
to-do list. Eshell also has pipes. The default pipe, which

00:17:29.214 --> 00:17:33.220
uses the familiar vertical bar symbol, pipes the data

00:17:33.221 --> 00:17:36.980
between the commands using an intermediate Emacs buffer.

00:17:36.981 --> 00:17:41.200
This, while usually quite practical, is less efficient

00:17:41.201 --> 00:17:46.319
than the system pipe. Therefore, Eshell also makes

00:17:46.320 --> 00:17:50.146
available a star-modified version, which uses the system

00:17:50.147 --> 00:17:52.546
pipe through a call to your system shell.

00:17:56.881 --> 00:17:59.413
So we can do things like

00:18:02.340 --> 00:18:05.860
direct output to a file.

00:18:15.100 --> 00:18:20.240
We're unfortunately not able to do input redirection, but

00:18:20.241 --> 00:18:22.540
we can use pipes.

00:18:41.760 --> 00:18:45.639
Elisp can manipulate and tie together processes in various

00:18:45.640 --> 00:18:50.999
ways, such as process filters and pipe processes, but I

00:18:51.000 --> 00:18:56.559
won't attempt to cover that. I feel like you should mention

00:18:56.560 --> 00:19:02.119
again that we have two kinds of pipes here available. So this

00:19:02.120 --> 00:19:09.239
pipe, the standard one, will pipe the data through Emacs

00:19:09.240 --> 00:19:16.759
buffers. That's very practical in most cases, but it is less

00:19:16.760 --> 00:19:22.919
efficient than piping through the system pipe. So Eshell

00:19:22.920 --> 00:19:28.119
makes available another symbol for that, star, vertical

00:19:28.120 --> 00:19:38.339
bar, that allows you to explicitly use the system pipe.

00:19:38.340 --> 00:19:43.599
Regarding scripting: Of course, using Emacs makes

00:19:43.600 --> 00:19:47.959
available all the power of the Elisp API and third-party

00:19:47.960 --> 00:19:54.719
packages, so we have that out of the gate. Eshell also has

00:19:54.720 --> 00:19:59.639
control flow statements, like an "if" construct and a "for"

00:19:59.640 --> 00:20:06.519
construct. See the Eshell info manual, section 3.7, for

00:20:06.520 --> 00:20:07.719
more details.

NOTE Scripts

00:20:09.440 --> 00:20:13.839
And if you wish to write a script entirely in Eshell syntax,

00:20:13.840 --> 00:20:18.559
and store it in a separate file, this is possible with recent

00:20:18.560 --> 00:20:20.159
versions of Emacs.

00:20:31.840 --> 00:20:34.679
Here's an example of a brief script that I wrote.

00:20:37.560 --> 00:20:42.679
Unfortunately, an eshell mode for proper syntax

00:20:42.680 --> 00:20:46.279
highlighting is not yet available, but hopefully that will

00:20:46.280 --> 00:20:51.279
be forthcoming. Note that Eshell syntax allows elisp

00:20:51.280 --> 00:20:55.079
forms to be interspersed with regular command form for

00:20:55.080 --> 00:20:58.759
additional scripting power. We will discuss this a little

00:20:58.760 --> 00:21:01.999
more later.

NOTE File system management

00:21:11.780 --> 00:21:16.759
Regarding file system management. In Emacs, many of the

00:21:16.760 --> 00:21:20.239
common file system operations are available as

00:21:20.240 --> 00:21:26.759
interactive commands. For example, M-x cd, to change your

00:21:26.760 --> 00:21:32.839
buffer's current working directory, and other M-x commands

00:21:32.840 --> 00:21:37.439
such as make-directory

00:21:40.780 --> 00:21:42.679
chmod,

00:21:43.260 --> 00:21:51.159
and delete-file. Of course, you can also drop into Eshell,

00:21:53.840 --> 00:22:00.639
or use M-x eshell-command to run the usual external commands

00:22:00.640 --> 00:22:07.039
for file system manipulation. Also, a file manager is built

00:22:07.040 --> 00:22:14.279
into Emacs, which can be run by calling M-x dired.

00:22:19.640 --> 00:22:24.559
The directory editor is powerful, but it is a bit strange to

00:22:24.560 --> 00:22:28.679
folks expecting something like Midnight Commander or the

00:22:28.680 --> 00:22:35.639
GNOME file manager. It gives us a number of helpful features

00:22:35.640 --> 00:22:43.639
like the ability to mark files, and to run elisp functions on

00:22:44.700 --> 00:22:48.439
them, and some other interesting ways to manipulate and

00:22:48.440 --> 00:22:54.079
rename the files. However, third-party Emacs extensions

00:22:54.080 --> 00:22:58.479
such as Midnight Commander Mode and Sunrise Commander are

00:22:58.480 --> 00:23:03.879
available to provide a Midnight Commander experience, for those who

00:23:03.880 --> 00:23:10.319
prefer that sort of file management.

00:23:10.320 --> 00:23:14.879
Emacs also has the nifty TRAMP functionality built in,

00:23:14.880 --> 00:23:19.159
which allows you, most of the time, to easily edit files on

00:23:19.160 --> 00:23:22.719
other computers, as well as manipulate the file system.

00:23:23.180 --> 00:23:27.839
This transparently works through SSH and some other

00:23:27.840 --> 00:23:30.079
protocols that you can specify.

NOTE Networking

00:23:43.560 --> 00:23:48.159
Regarding networking features, I don't have a lot of

00:23:48.160 --> 00:23:51.639
interesting things to say about this at the present, so I'll

00:23:51.640 --> 00:23:54.919
skip through this quickly. But if you do a little research,

00:23:54.920 --> 00:23:58.799
you will see that Emacs has a lot of functionality relating

00:23:58.800 --> 00:24:02.359
to making network connections, interacting with the web,

00:24:02.780 --> 00:24:07.859
and such like, both built-in and in available packages, as

00:24:07.860 --> 00:24:14.399
well as modes for doing things like Web browsing and Gemini

00:24:14.400 --> 00:24:20.599
browsing. And of course, you can run the usual standard

00:24:20.600 --> 00:24:23.639
networking commands for your system through Eshell.

NOTE A brief tour of Eshell

00:24:30.120 --> 00:24:33.759
So having put forward the main arguments for this talk, I

00:24:33.760 --> 00:24:38.199
would like to take some time now to give a brief tour of a few of

00:24:38.200 --> 00:24:43.799
the features of Eshell, the Emacs shell. It bears

00:24:43.800 --> 00:24:46.999
emphasizing that Eshell is not a drop-in replacement for

00:24:47.000 --> 00:24:51.879
Bash, or even a Bash clone, though I believe the developers

00:24:51.880 --> 00:24:56.839
are trying to make much of the syntax very similar. Also,

00:24:56.840 --> 00:25:00.479
Eshell is not a terminal emulator, and it will not display

00:25:00.480 --> 00:25:04.679
correctly applications which use advanced ANSI control

00:25:04.680 --> 00:25:10.119
codes. However, Eshell can be configured to be aware of such

00:25:10.120 --> 00:25:13.300
applications, and to run them automatically within the

00:25:13.301 --> 00:25:19.940
Emacs terminal emulator when launched. See section 5.1 of

00:25:19.941 --> 00:25:24.100
the Eshell manual titled Visual Commands.

00:25:32.540 --> 00:25:36.759
Though Eshell is not Bash, it has multiple features,

00:25:36.760 --> 00:25:40.679
pertaining mainly to its by-design Emacs integration,

00:25:40.680 --> 00:25:44.639
which may make it more appealing to use than Bash or another

00:25:44.640 --> 00:25:45.359
shell.

00:25:48.160 --> 00:25:52.039
For one, Eshell allows entering commands on the command

00:25:52.040 --> 00:25:55.960
line that are space and new line separated, without

00:25:55.961 --> 00:26:01.280
parentheses. Of course, all the other shells do this. But

00:26:01.281 --> 00:26:06.280
within Eshell, it is possible to enter internal Emacs

00:26:06.281 --> 00:26:11.060
functions, as well as external commands.

00:26:13.240 --> 00:26:45.739
This allows us to do things like this.

00:26:45.740 --> 00:26:49.759
As far as I understand, it is possible to enter any Emacs

00:26:49.760 --> 00:26:53.959
function on the Eshell command line. However, some special

00:26:53.960 --> 00:26:58.399
syntax may be required if you are trying to pass in something

00:26:58.400 --> 00:27:00.799
that is not a string or a number.

00:27:04.380 --> 00:27:07.919
As you might have noticed in the last example, Eshell makes

00:27:07.920 --> 00:27:12.919
it possible to use an Emacs buffer as a sink for output. It

00:27:12.920 --> 00:27:18.039
also allows using a buffer as a source of input, though this

00:27:18.040 --> 00:27:21.839
is slightly more complicated, since the buffer must be

00:27:21.840 --> 00:27:27.199
converted to a string first. I have distilled this down into

00:27:27.200 --> 00:27:30.279
my own function, named with the "at" symbol.

00:27:36.640 --> 00:27:40.319
And I will provide the brief snippet of code for this later.

00:27:54.640 --> 00:28:02.499
So to give an example, here's our messages buffer.

00:28:02.500 --> 00:28:05.399
And from Eshell, we can do something like this.

00:28:29.780 --> 00:28:34.439
Let's say here we wanted to grab our messages buffer to see

00:28:34.440 --> 00:28:38.079
everything that we had been loading during the startup

00:28:38.080 --> 00:28:38.959
process.

00:28:48.060 --> 00:28:51.879
So you can see how that could be very handy in a number of

00:28:51.880 --> 00:28:52.959
scenarios.

00:28:55.060 --> 00:29:00.239
I wanted to briefly mention that we have a helpful function

00:29:00.240 --> 00:29:03.439
here called eshell-insert-buffer-name,

00:29:11.120 --> 00:29:15.359
which allows us to insert a buffer name into the current

00:29:15.360 --> 00:29:18.439
buffer at point using completion,

00:29:24.680 --> 00:29:32.879
which can save you a lot of typing.

00:29:32.880 --> 00:29:34.799
Another nice feature of Eshell

00:29:37.220 --> 00:29:41.199
is that it allows integrating ELisp into the command line

00:29:41.200 --> 00:29:48.879
call. Let's give another example. Say we wanted to echo the

00:29:48.880 --> 00:29:53.919
date to an event file or an event log.

00:29:56.720 --> 00:30:01.639
I should probably take a moment to explain this asterisk

00:30:01.640 --> 00:30:06.999
that I'm occasionally using. So since Emacs, or excuse me,

00:30:07.000 --> 00:30:11.719
since Eshell can use internal or external Emacs, excuse me,

00:30:11.720 --> 00:30:16.999
internal Emacs commands or external commands, it may

00:30:17.000 --> 00:30:21.679
sometimes be necessary to clarify which one you want to use,

00:30:22.380 --> 00:30:27.079
since the names may overlap. Since my Eshell is configured

00:30:27.080 --> 00:30:32.319
by default to prefer the internal Emacs functions, then

00:30:32.320 --> 00:30:37.799
sometimes I have to use the asterisk to specify that I want

00:30:37.800 --> 00:30:39.079
the external version.

00:30:42.680 --> 00:31:02.639
Here I can insert a bit of Elisp,

00:31:03.180 --> 00:31:06.119
and then redirect the output to the event log.

00:31:18.720 --> 00:31:22.639
Last, I want to mention that there are some optional Eshell

00:31:22.640 --> 00:31:27.159
modules in Emacs, not turned on by default, which provide

00:31:27.160 --> 00:31:29.039
additional nifty features.

00:31:40.540 --> 00:31:45.639
On my system, I have most of the optional modules turned on.

00:31:58.320 --> 00:32:03.199
An interesting module is eshell-smart, which does various

00:32:03.200 --> 00:32:07.319
things with cursor positioning and scrolling, so as to make

00:32:07.320 --> 00:32:10.399
editing commands and reviewing output easier.

00:32:18.340 --> 00:32:23.619
Let's say I was to change directory to my boot directory

00:32:30.880 --> 00:32:35.039
and use a command which involves lots of output.

00:32:39.900 --> 00:32:44.359
You'll notice right away that the cursor positioning is set

00:32:44.360 --> 00:32:48.719
such that I'm immediately able to view the top of the output.

00:32:48.720 --> 00:32:52.879
Also, I'm able to use the space bar to page through the

00:32:52.880 --> 00:32:56.079
output.

00:32:56.080 --> 00:33:01.919
So this is an opinionated feature, which assumes that

00:33:01.920 --> 00:33:05.399
you're likely going to want to review the output

00:33:05.400 --> 00:33:10.559
immediately, or that you often will. Of course, you can

00:33:10.560 --> 00:33:17.599
always jump to the end.

00:33:19.980 --> 00:33:23.919
Also, after a command is entered, the cursor is immediately

00:33:23.920 --> 00:33:28.279
repositioned to make it easy to edit the command.

00:33:53.020 --> 00:33:56.519
And also, if I don't want to edit the command, and I do not want

00:33:56.520 --> 00:33:59.679
to review the output, I can simply start typing another

00:33:59.680 --> 00:34:00.359
command.

00:34:11.260 --> 00:34:15.519
So that covers the brief tour of Eshell features.

00:34:17.760 --> 00:34:21.127
And that basically ends my talk.

NOTE Login shell

00:34:21.128 --> 00:34:22.380
However, a handful of

00:34:22.381 --> 00:34:28.719
viewers might be wondering, is it possible to set Emacs to be

00:34:28.720 --> 00:34:37.639
my login shell to completely replace bash in your login

00:34:37.640 --> 00:34:43.719
experience? The answer is yes, but in practice there are

00:34:43.720 --> 00:34:47.399
various difficulties involved which might make it not

00:34:47.400 --> 00:34:48.359
worth the trouble.

00:35:00.440 --> 00:35:03.479
Before doing this, you'll have to answer a few initial

00:35:03.480 --> 00:35:09.519
questions. Do you want to make a new Emacs instance every

00:35:09.520 --> 00:35:13.759
time you log in, or do you want it to connect to an Emacs

00:35:13.760 --> 00:35:20.599
server? Which is popular among Emacs users, to reuse the

00:35:20.600 --> 00:35:26.599
session, or to connect to the existing session. Also, do you

00:35:26.600 --> 00:35:30.639
want a different result, whether in graphical or a terminal

00:35:30.640 --> 00:35:34.679
environment? And are you okay with your initialization

00:35:34.680 --> 00:35:39.559
file being run every time you log in, including every new tab

00:35:39.560 --> 00:35:44.520
you open in a terminal emulator? If we assume that you are

00:35:44.521 --> 00:35:50.339
using a system with /etc/passwd user management, you get

00:35:50.340 --> 00:35:53.999
one field to specify the name of the shell program that you

00:35:54.000 --> 00:35:58.479
want to use, and no arguments are allowed. So maybe you can

00:35:58.480 --> 00:36:02.679
see how this might be challenging, depending on your

00:36:02.680 --> 00:36:06.879
answers to the previous questions. You can work around

00:36:06.880 --> 00:36:10.479
these issues in various ways, like modifying the

00:36:10.480 --> 00:36:15.439
authentication system, or by specifying a script for your

00:36:15.440 --> 00:36:21.799
login shell. But if your normal workflow is to simply log in

00:36:21.800 --> 00:36:25.679
and start Emacs and run that Emacs session until your next

00:36:25.680 --> 00:36:36.979
reboot, then it probably isn't worth the bother.

NOTE Resources

00:36:36.980 --> 00:36:41.999
So thank you for listening to my talk, Emacs as a Shell, by

00:36:42.000 --> 00:36:46.319
Christopher Howard for Emacs Conference 2024.

00:36:46.860 --> 00:36:51.519
At the bottom of this page, you can see a link to the

00:36:51.520 --> 00:36:56.919
repository containing the brief amount of code that was

00:36:56.920 --> 00:37:03.679
featured here in this video, as well as a link to my personal

00:37:03.680 --> 00:37:10.279
Gemini gemlog, as well as to a Web portal version of that.

00:37:10.280 --> 00:37:13.000
Thank you.