diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5e77865 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Alex Perathoner + +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. diff --git a/PercentageIncrease.xcodeproj/project.pbxproj b/PercentageIncrease.xcodeproj/project.pbxproj new file mode 100644 index 0000000..8f40438 --- /dev/null +++ b/PercentageIncrease.xcodeproj/project.pbxproj @@ -0,0 +1,289 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + FAA37D6123C9244C000397D0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA37D6023C9244C000397D0 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + FAA37D5B23C9244C000397D0 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + FAA37D5D23C9244C000397D0 /* PercentageIncrease */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PercentageIncrease; sourceTree = BUILT_PRODUCTS_DIR; }; + FAA37D6023C9244C000397D0 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + FAA37D5A23C9244C000397D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + FAA37D5423C9244C000397D0 = { + isa = PBXGroup; + children = ( + FAA37D5F23C9244C000397D0 /* PercentageIncrease */, + FAA37D5E23C9244C000397D0 /* Products */, + ); + sourceTree = ""; + }; + FAA37D5E23C9244C000397D0 /* Products */ = { + isa = PBXGroup; + children = ( + FAA37D5D23C9244C000397D0 /* PercentageIncrease */, + ); + name = Products; + sourceTree = ""; + }; + FAA37D5F23C9244C000397D0 /* PercentageIncrease */ = { + isa = PBXGroup; + children = ( + FAA37D6023C9244C000397D0 /* main.swift */, + ); + path = PercentageIncrease; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + FAA37D5C23C9244C000397D0 /* PercentageIncrease */ = { + isa = PBXNativeTarget; + buildConfigurationList = FAA37D6423C9244C000397D0 /* Build configuration list for PBXNativeTarget "PercentageIncrease" */; + buildPhases = ( + FAA37D5923C9244C000397D0 /* Sources */, + FAA37D5A23C9244C000397D0 /* Frameworks */, + FAA37D5B23C9244C000397D0 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PercentageIncrease; + productName = PercentageIncrease; + productReference = FAA37D5D23C9244C000397D0 /* PercentageIncrease */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + FAA37D5523C9244C000397D0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1130; + LastUpgradeCheck = 1130; + ORGANIZATIONNAME = "Alex Perathoner"; + TargetAttributes = { + FAA37D5C23C9244C000397D0 = { + CreatedOnToolsVersion = 11.3; + }; + }; + }; + buildConfigurationList = FAA37D5823C9244C000397D0 /* Build configuration list for PBXProject "PercentageIncrease" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = FAA37D5423C9244C000397D0; + productRefGroup = FAA37D5E23C9244C000397D0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + FAA37D5C23C9244C000397D0 /* PercentageIncrease */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + FAA37D5923C9244C000397D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FAA37D6123C9244C000397D0 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + FAA37D6223C9244C000397D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + FAA37D6323C9244C000397D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + FAA37D6523C9244C000397D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = XX9N244QQT; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + FAA37D6623C9244C000397D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = XX9N244QQT; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + FAA37D5823C9244C000397D0 /* Build configuration list for PBXProject "PercentageIncrease" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FAA37D6223C9244C000397D0 /* Debug */, + FAA37D6323C9244C000397D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + FAA37D6423C9244C000397D0 /* Build configuration list for PBXNativeTarget "PercentageIncrease" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FAA37D6523C9244C000397D0 /* Debug */, + FAA37D6623C9244C000397D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = FAA37D5523C9244C000397D0 /* Project object */; +} diff --git a/PercentageIncrease.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PercentageIncrease.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..39828fc --- /dev/null +++ b/PercentageIncrease.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/PercentageIncrease.xcodeproj/xcuserdata/alex.xcuserdatad/xcschemes/xcschememanagement.plist b/PercentageIncrease.xcodeproj/xcuserdata/alex.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..dc68727 --- /dev/null +++ b/PercentageIncrease.xcodeproj/xcuserdata/alex.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + PercentageIncrease.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/PercentageIncrease/main.swift b/PercentageIncrease/main.swift new file mode 100644 index 0000000..7f1e85b --- /dev/null +++ b/PercentageIncrease/main.swift @@ -0,0 +1,39 @@ +// +// main.swift +// PercentageIncrease +// +// Created by Alex Perathoner on 10/01/2020. +// Copyright © 2020 Alex Perathoner. All rights reserved. +// + +import Foundation + + +func abs(_ r: Double) -> Double { + if(r<0) {return r*(-1)} + return r +} + +func roundToPlaces(value:Double, places:Int) -> Double { + let divisor = pow(10.0, Double(places)) + return round(value * divisor) / divisor +} + +var n1: Double?, n2: Double? +let arguments = CommandLine.arguments +if CommandLine.argc == 3 { + n1 = Double(arguments[1]) + n2 = Double(arguments[2]) +} else { + print("Insert starting value: ") + n1 = Double(readLine()!) + n2 = Double(readLine()!) +} + + +if n1 != nil && n2 != nil { + let increase = roundToPlaces(value: ((n2! - n1!)/abs(n1!)*100), places: 3) + print("Increase of: " + increase.description + "%") +} else { + print("Insert valid values!") +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a93d1e9 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# PercentageIncrease + +A handy Command Line App to quickly calculate the increase (or decrease) from a starting to a final value. + +## Getting started +Download the [latest release](https://github.com/AlexPerathoner/PercentageIncrease/releases/latest) and follow the instructions. + +### Installing +The package will do the following things: + +* Copy a terminal executable called "PercentageIncrease" in your Applications folder +* Execute a script which will append the following lines to the .zshenv file in your home directory: + + ``` + alias %="/Applications/PercentageIncrease" + alias increase="/Applications/PercentageIncrease" + ``` + This will allow you to run **PercentageIncrease** just by typing ```%``` or ```increase``` inside your terminal. + + **Note:** ```%``` may conflict with terminal scripts using fg. If so delete the first line in ~/.zshenv. + +### How to use +You have two ways to calculate the increase in percentage using **PercentageIncrease**: + + +* **With parameters** + + Type ```% ``` or ```increase ``` followed by the starting and the final values. + + Example: ```% 2 3``` returns: ```Increase of: 50.0%``` + ![ExampleImage](https://github.com/AlexPerathoner/PercentageIncrease/blob/master/Resources/Screen1.?raw=true) +* **Without parameters** + + Type ```%``` or ```increase ``` and press enter. You will now prompted to insert the starting and the final values. + + Insert one after the other the two values the two values and press enter. + + Example: + ![ExampleImage](https://github.com/AlexPerathoner/PercentageIncrease/blob/master/Resources/Screen2.?raw=true) + + + + + + +## License + +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details + +--- +Donations are welcome! + +[![Donate-Paypal](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat)](https://paypal.me/AlexanderPerathoner) \ No newline at end of file diff --git a/Resources/PercentageIncreaseIcon.png b/Resources/PercentageIncreaseIcon.png new file mode 100644 index 0000000..3c59490 Binary files /dev/null and b/Resources/PercentageIncreaseIcon.png differ diff --git a/Resources/Screen1.png b/Resources/Screen1.png new file mode 100644 index 0000000..47ca10b Binary files /dev/null and b/Resources/Screen1.png differ diff --git a/Resources/Screen2.png b/Resources/Screen2.png new file mode 100644 index 0000000..1710914 Binary files /dev/null and b/Resources/Screen2.png differ