Skip to content

Commit 487c17f

Browse files
author
⚙︎ Greg
committed
0.0.2
1 parent e085100 commit 487c17f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1543
-0
lines changed

.gitignore

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/.vs/
2+
.vscode
3+
/.paket/
4+
/packages/
5+
/paket-files/
6+
7+
#################
8+
## Eclipse
9+
#################
10+
11+
*.pydevproject
12+
.project
13+
.metadata
14+
bin/
15+
tmp/
16+
*.tmp
17+
*.bak
18+
*.swp
19+
*~.nib
20+
local.properties
21+
.classpath
22+
.settings/
23+
.loadpath
24+
25+
# External tool builders
26+
.externalToolBuilders/
27+
28+
# Locally stored "Eclipse launch configurations"
29+
*.launch
30+
31+
# CDT-specific
32+
.cproject
33+
34+
# PDT-specific
35+
.buildpath
36+
37+
38+
#################
39+
## Visual Studio
40+
#################
41+
42+
## Ignore Visual Studio temporary files, build results, and
43+
## files generated by popular Visual Studio add-ons.
44+
45+
# User-specific files
46+
*.suo
47+
*.user
48+
*.sln.docstates
49+
50+
# Build results
51+
52+
[Dd]ebug/
53+
[Rr]elease/
54+
x64/
55+
build/
56+
[Bb]in/
57+
[Oo]bj/
58+
59+
# MSTest test Results
60+
[Tt]est[Rr]esult*/
61+
[Bb]uild[Ll]og.*
62+
63+
*_i.c
64+
*_p.c
65+
*.ilk
66+
*.meta
67+
*.obj
68+
*.pch
69+
*.pdb
70+
*.pgc
71+
*.pgd
72+
*.rsp
73+
*.sbr
74+
*.tlb
75+
*.tli
76+
*.tlh
77+
*.tmp
78+
*.tmp_proj
79+
*.log
80+
*.vspscc
81+
*.vssscc
82+
.builds
83+
*.pidb
84+
*.log
85+
*.scc
86+
87+
# Visual C++ cache files
88+
ipch/
89+
*.aps
90+
*.ncb
91+
*.opensdf
92+
*.sdf
93+
*.cachefile
94+
95+
# Visual Studio profiler
96+
*.psess
97+
*.vsp
98+
*.vspx
99+
100+
# Guidance Automation Toolkit
101+
*.gpState
102+
103+
# ReSharper is a .NET coding add-in
104+
_ReSharper*/
105+
*.[Rr]e[Ss]harper
106+
107+
# TeamCity is a build add-in
108+
_TeamCity*
109+
110+
# DotCover is a Code Coverage Tool
111+
*.dotCover
112+
113+
# NCrunch
114+
*.ncrunch*
115+
.*crunch*.local.xml
116+
117+
# Installshield output folder
118+
[Ee]xpress/
119+
120+
# DocProject is a documentation generator add-in
121+
DocProject/buildhelp/
122+
DocProject/Help/*.HxT
123+
DocProject/Help/*.HxC
124+
DocProject/Help/*.hhc
125+
DocProject/Help/*.hhk
126+
DocProject/Help/*.hhp
127+
DocProject/Help/Html2
128+
DocProject/Help/html
129+
130+
# Click-Once directory
131+
publish/
132+
133+
# Publish Web Output
134+
*.Publish.xml
135+
*.pubxml
136+
*.publishproj
137+
138+
# NuGet Packages Directory
139+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
140+
#packages/
141+
142+
# Windows Azure Build Output
143+
csx
144+
*.build.csdef
145+
146+
# Windows Store app package directory
147+
AppPackages/
148+
149+
# Others
150+
sql/
151+
*.Cache
152+
ClientBin/
153+
[Ss]tyle[Cc]op.*
154+
~$*
155+
*~
156+
*.dbmdl
157+
*.[Pp]ublish.xml
158+
*.pfx
159+
*.publishsettings
160+
161+
# RIA/Silverlight projects
162+
Generated_Code/
163+
164+
# Backup & report files from converting an old project file to a newer
165+
# Visual Studio version. Backup files are not needed, because we have git ;-)
166+
_UpgradeReport_Files/
167+
Backup*/
168+
UpgradeLog*.XML
169+
UpgradeLog*.htm
170+
171+
# SQL Server files
172+
App_Data/*.mdf
173+
App_Data/*.ldf
174+
175+
#############
176+
## Windows detritus
177+
#############
178+
179+
# Windows image file caches
180+
Thumbs.db
181+
ehthumbs.db
182+
183+
# Folder config file
184+
Desktop.ini
185+
186+
# Recycle Bin used on file shares
187+
$RECYCLE.BIN/
188+
189+
# Mac crap
190+
.DS_Store
191+
192+
193+
#############
194+
## Python
195+
#############
196+
197+
*.py[cod]
198+
199+
# Packages
200+
*.egg
201+
*.egg-info
202+
dist/
203+
build/
204+
eggs/
205+
parts/
206+
var/
207+
sdist/
208+
develop-eggs/
209+
.installed.cfg
210+
211+
# Installer logs
212+
pip-log.txt
213+
214+
# Unit test / coverage reports
215+
.coverage
216+
.tox
217+
218+
#Translations
219+
*.mo
220+
221+
#Mr Developer
222+
.mr.developer.cfg
223+
224+
.fake

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,123 @@
11
# FsShell
22
List of Shell-like commands for use in F#.
3+
4+
## Caveat
5+
These commands are NOT intended for projects with a long life. It is recommended that this only be used in the FSI or for short fire-and-forget utilities. As I eat my own dog food and become more proficient in idiomatic F#, some things might change.
6+
7+
## Usage
8+
```F#
9+
#r "nuget:FsShell"
10+
open FsShell
11+
man "";;
12+
13+
System
14+
cd Change directory
15+
pwd Print working directory
16+
mkdir Make directory
17+
mv Move file
18+
cp Copy file
19+
ls List
20+
ll List with details (fullname * size * FileInfo)
21+
find Find files
22+
find_p Find folders
23+
Output
24+
stdout Output to STDOUT
25+
stderr Output to STDERR
26+
write Output to a file
27+
append Append to a file
28+
tee Output to a file and passthrough
29+
tee_a Append to a file and passthrough
30+
cat Read a list of files consecutively
31+
Data Manipulation
32+
NOTE: these will create seq<string list> that aren't friendly with other commands
33+
cut Split lines at tabs
34+
cut_d Split lines at delimeter
35+
cut_c Cut character range options
36+
cut_c2 Cut character ranges
37+
cutx Splits CSV into columns
38+
Data Flow
39+
grep Filter lines to include
40+
grep_i Filter lines to include, case insensitive
41+
egrep Filter lines to include with regex
42+
egrep_i Filter lines to include with regex, case insensitive
43+
grep_n Filter lines to exclude
44+
grep_in Filter lines to exclude, case insensitive
45+
egrep_n Filter lines to exclude with regex
46+
egrep_in Filter lines to exclude with regex, case insensitive
47+
head_n First count lines
48+
head First 10 lines
49+
tail_n Last count lines, or skip first count of lines
50+
tail Last 10 lines
51+
Miscellaneous
52+
man This
53+
```
54+
55+
[All functions are in FsShell.fs](src/FsShell/FsShell.fs)
56+
57+
## Examples
58+
59+
### Manipulating Folders
60+
```F#
61+
> mkdir "test_fsshell";;
62+
val it: string = "/Users/gregh/Projects/test_fsshell"
63+
64+
> cd "test_fsshell";;
65+
val it: string = "/Users/gregh/Projects/test_fsshell"
66+
67+
> pwd ();;
68+
val it: string = "/Users/gregh/Projects/test_fsshell"
69+
```
70+
71+
### Manipulating Files
72+
```F#
73+
> // write to output lines to files
74+
- // newlines are added and stripped automatically
75+
- seq {
76+
- "My First Line"
77+
- "My Second Line"
78+
- }
79+
- |> write "file1.txt"
80+
- ;;
81+
val it: unit = ()
82+
83+
> // cat and grep
84+
- cat [ "file1.txt" ]
85+
- |> grep_i "second"
86+
- |> write "file2.txt"
87+
- ;;
88+
val it: unit = ()
89+
90+
> cat [ "file1.txt"; "file2.txt" ];;
91+
val it: seq<string> =
92+
seq ["My First Line"; "My Second Line"; "My Second Line"]
93+
```
94+
95+
### Manipulating Data
96+
```F#
97+
> seq { "A\tB"; "C\tD" } |> write "file1.txt";;
98+
val it: unit = ()
99+
100+
> cat [ "file1.txt" ]
101+
- |> cut
102+
- ;;
103+
val it: seq<string list> = seq [["A"; "B"]; ["C"; "D"]]
104+
> // also available is cut_d to split on a provided delimiter
105+
- // cut_c and cut_c2 to get specific character ranges
106+
107+
> // cutx for handling CSV data files
108+
- cat [ "./datafile.csv" ]
109+
- |> cutx
110+
- ;;
111+
val it: seq<string array> =
112+
seq
113+
[[|"Column 1"; "Column 2"; "Column 3"|];
114+
[|"Val 1-1"; "Val 2-1"; "Val 3-1"|];
115+
[|"Val 1-2"; "Val 2-2"; "Val 3-2"|];
116+
[|"Val 1-3"; "Val 2-3"; "Val 3-3"|]]
117+
```
118+
119+
## Miscellaneous
120+
121+
### "Why no rm and rmdir?"
122+
123+
I could see this going badly, quickly. Maybe I'll change my mind later, but after implementing it, I felt it was too dangerous.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module SpiralOSS.FsShell.Testing.Command.CatTests
2+
3+
open Xunit
4+
open System.Linq
5+
open SpiralOSS.FsShell.Testing.Infrastructure
6+
open SpiralOSS.FsShell.Command.Cat
7+
8+
[<Fact>]
9+
let ``Test Cat 1 File`` () =
10+
use tempFile = new Utility.AutoDeletingTempFile ()
11+
tempFile.write Utility.sampleTextSeq
12+
let expect = Utility.sampleTextSeq
13+
let actual = cat System.Text.Encoding.UTF8 [ tempFile.filename ]
14+
Assert.True(expect.SequenceEqual(actual));
15+
16+
[<Fact>]
17+
let ``Test Cat 2 Files`` () =
18+
use tempFile1 = new Utility.AutoDeletingTempFile ()
19+
use tempFile2 = new Utility.AutoDeletingTempFile ()
20+
tempFile1.write Utility.sampleTextSeq
21+
tempFile2.write Utility.sampleTextSeq
22+
let expect = seq { yield! Utility.sampleTextSeq; yield! Utility.sampleTextSeq }
23+
let actual = cat System.Text.Encoding.UTF8 [ tempFile1.filename; tempFile2.filename ]
24+
Assert.True(expect.SequenceEqual(actual));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module SpiralOSS.FsShell.Testing.Command.CdTests
2+
3+
open Xunit
4+
open System.IO
5+
open SpiralOSS.FsShell.Command.Cd
6+
7+
[<Fact>]
8+
let ``Test Cd`` () =
9+
let expected = Path.GetDirectoryName (Directory.GetCurrentDirectory ())
10+
let actual = cd ".."
11+
Assert.Equal(expected, actual)

0 commit comments

Comments
 (0)