Skip to content

Instantly share code, notes, and snippets.

View leogdion's full-sized avatar

leogdion leogdion

View GitHub Profile
#!/bin/bash
SOURCE_DIR="/path/to/your/source/directory"
find "$SOURCE_DIR" -name "*.swift" -type f -print0 | while IFS= read -r -d '' file; do
# Create a temporary file for editing
tmp_file=$(mktemp)
# Use awk to perform the replacement and save to the temporary file
awk '
//
// FileManager+ReduceDirectory.swift
// Copyright (c) 2023 BrightDigit.
//
import Foundation
private extension Error where Self == NSError {
static func fileNotFound(at url: URL) -> NSError {
NSError(
@leogdion
leogdion / PreferredLayoutView.swift
Created September 14, 2023 16:51
Use GeometryReader to Save a Value and Reuse It
//
// PreferredLayoutView.swift
// Copyright (c) 2023 BrightDigit.
//
#if canImport(SwiftUI)
import Foundation
import SwiftUI
public struct Value<Value> {
@leogdion
leogdion / NSWindowDelegateAdaptor.swift
Created August 23, 2023 14:20
How to tap into the NSWindowDelegate
import AppKit
import SwiftUI
// .onCloseButton(self.$object.delegate, { _ in
// self.object.presentConfirmCloseAlert = true
// return false
// })
class NSWindowDelegateAdaptor: NSObject, NSWindowDelegate {
internal init(onWindowShouldClose: ((NSWindow) -> Bool)?) {
@leogdion
leogdion / NSWindowAdaptorModifier.swift
Created August 17, 2023 21:49
Allow SwiftUI to modifier NSWindow
//
// NSWindowAdaptorModifier.swift
// Copyright (c) 2023 BrightDigit.
//
import AppKit
import Foundation
import SwiftUI
// swiftlint:disable strict_fileprivate
@leogdion
leogdion / PackageUI.swift
Created July 21, 2023 20:30
Swift DSL for Package.swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
// add this to beginning of your Package.swift
import PackageDescription
// MARK: SupportedPlatform
protocol SupportedPlatformable {
#!/bin/bash
tmpfile=$(mktemp)
branch=${1:-main}
logfileslst=$(mktemp)
echo -n "Compiling list of changes..."
git diff --name-only $1 HEAD | while read -r file; do
logfile=$(mktemp)
@leogdion
leogdion / brew_detect.sh
Last active February 10, 2023 19:02
Detect Brew Prefix If Needed
#!/bin/bash
BREW_PATH="$(which brew)"
BREW_PATH_RESULT=$?
if [[ $BREW_PATH_RESULT -ne 0 ]] || [[ -z "$BREW_PATH" ]]; then
echo "It looks like Homebrew is not already installed."
echo "Finding path where it will be..."
arch="$(arch)" # -i is only linux, -m is linux and apple
if [[ "$arch" = i386 ]]; then
@leogdion
leogdion / swift-apt-repo-install.sh
Last active September 10, 2022 16:43 — forked from futurejones/swift-apt-repo-install.sh
Install script for the Swift Community Apt Repository - https://archive.swiftlang.xyz
#! /bin/bash
#
# Install script for the Swift Community Apt Repository - swiftlang.xyz
#
# check distribution version and infer distro with switch/case
## as all distribution versions have different names we can use this information to infer the distribution name.
check_ver () {
for var in "${SUPPORTED_VER[@]}"
do
#!/bin/bash
DEST_REPO=$1
DEST_BRANCH=$2
MESSAGE=$(git log -1 HEAD --pretty=format:%s)
SOURCE_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
git remote add destination $DEST_REPO
git fetch --all
git checkout -b destination-merging SOURCE_BRANCH