Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Henrik Panhans <henrik@panhans.dev>
  • Loading branch information
henrik-dmg committed Jan 19, 2024
0 parents commit 1eab818
Show file tree
Hide file tree
Showing 26 changed files with 1,363 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
run-tests:
runs-on: macos-13

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
.swiftpm
5 changes: 5 additions & 0 deletions .periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
targets:
- FileOrganiser
- FileOrganiserKit
- FileOrganiserKitTests
enable_unused_import_analysis: true
67 changes: 67 additions & 0 deletions .swift-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": true,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": true,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": true,
"lineLength": 140,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": ["XCTAssertNoThrow"]
},
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": true,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": true,
"NeverUseForceTry": true,
"NeverUseImplicitlyUnwrappedOptionals": true,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": true,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": true,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": true
},
"spacesAroundRangeFormationOperators": true,
"tabWidth": 4,
"version": 1
}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Henrik Panhans

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"pins" : [
{
"identity" : "clifoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/henrik-dmg/CLIFoundation",
"state" : {
"branch" : "main",
"revision" : "ebfaae5ff163d99e7a68b0827446677984b244c4"
}
},
{
"identity" : "globpattern",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/GlobPattern",
"state" : {
"branch" : "main",
"revision" : "c7c3d7864b24543343d7cac9a27fab4ad17410a2"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
}
],
"version" : 2
}
52 changes: 52 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "FileOrganiser",
platforms: [
.macOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.executable(
name: "file-organiser",
targets: ["FileOrganiser"]
),
.library(
name: "FileOrganiserKit",
targets: ["FileOrganiserKit"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/henrik-dmg/CLIFoundation", branch: "main"),
.package(url: "https://github.com/ChimeHQ/GlobPattern", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "FileOrganiserKit",
dependencies: [
"CLIFoundation",
"GlobPattern",
]
),
.testTarget(
name: "FileOrganiserKitTests",
dependencies: [
"FileOrganiserKit"
]
),
.executableTarget(
name: "FileOrganiser",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"FileOrganiserKit",
]
),
]
)
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# FileOrganiser

A CLI tool to organise files into folders based on their creation date.

## Installation

### Homebrew

```bash
brew install file-organiser
```

### Manual

```bash
git clone https://github.com/henrik-dmg/FileOrganiser.git
cd FileOrganiser
swift build -c release
ln -s .build/release/file-organiser /usr/local/bin/file-organiser # or any other directory in your $PATH
```

## Usage

The tool has two subcommands: `copy` and `move`. If you use `copy`, source files will remain in their original location. If you use `move`, source files will be moved to the target directory to you the original folder structure will be lost.
The options and arguments are the same for both.

Example:

```bash
file-organiser move ~/Some/Source/Directory ~/Some/Target/Directory --date-strategy year
```

### Options

#### `--file-pattern`

An optional file name pattern. Only files matching this pattern will be moved or copied.

#### `--date-strategy`

The strategy with which files are grouped into subfolders. For the available options, please refer to the section [Date Grouping Strategies](#date-grouping-strategies).

#### `--dry-run`

Only print the actions that would be performed, but do not actually perform them

#### `--verbose`

Prints additional information during processing

#### `--soft-fail`

Keeps the tool running when a failure occurs for individual files

## Date Grouping Strategies

Files are grouped by their creation date. The following strategies are available:

### `year`

The most basic option. It will simply create one folder for every year.
Example:

```
.
├── 2022
│   ├── file-from-2022
│   └── other-file-from-2022
├── 2023
│   ├── file-from-2023
│   └── other-file-from-2022
└── 2024
├── file-from-2024
└── other-file-from-2024
```

### `month`

Similar to `year`, but files will be moved into subfolders for each month as well. This is the default option. I use this option to organise my photos from my camera for example.
Example:

```
.
├── 2022
│   ├── 04
│   │   ├── file-from-april-2022
│   └── 08
│   └── other-file-from-august-2022
├── 2023
│   └── 07
│      └── file-from-july-2023
└── 2024
├── 10
│   └── file-from-october-2024
└── 12
└── other-file-from-december-2024
```

### `day`

Similar to `month`, but files will be moved into subfolders for each day as well.
I guess this one is not very useful unless you create a lot of files every day.
Specifying `month` will result in the following folder structure:

```
.
├── 2022
│   ├── 04
│   │   └── 2024-04-01
| │      └── file-from-april-01-2022
│   └── 08
│   └── 2024-08-29
│   └── file-from-august-29-2022
└── 2024
├── 10
│   └── 2024-10-16
│   └── file-from-october-16-2024
└── 12
└── 2024-12-31
└── file-from-december-31-2024
```

## Contributing

If you have any ideas for improvements, please feel free to open an issue or a pull request :)
10 changes: 10 additions & 0 deletions Scripts/configure-hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

GIT_ROOT=$(git rev-parse --show-toplevel)

# Check if the pre-commit hook already exists
if [ -f "$GIT_ROOT/.git/hooks/pre-commit" ]; then
rm "$GIT_ROOT/.git/hooks/pre-commit"
fi

ln -s "$GIT_ROOT/Scripts/lint-swift-code" "$GIT_ROOT/.git/hooks/pre-commit"
10 changes: 10 additions & 0 deletions Scripts/format-swift-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

swift-format format \
--recursive \
--parallel \
--in-place \
--configuration .swift-format.json \
Sources/ \
Tests/ \
Package.swift
10 changes: 10 additions & 0 deletions Scripts/lint-swift-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

swift-format lint \
--recursive \
--parallel \
--strict \
--configuration .swift-format.json \
Sources/ \
Tests/ \
Package.swift
Loading

0 comments on commit 1eab818

Please sign in to comment.