Skip to content

Commit

Permalink
Merge pull request #1 from VladBrok/linux-support
Browse files Browse the repository at this point in the history
Linux support
  • Loading branch information
VladBrok authored Sep 18, 2022
2 parents 2d492be + 87abbfc commit 3a734b0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 44 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Fast navigation between directories
- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Linux](#linux)
- [Windows](#windows)
- [Usage](#usage)
- [License](#license)

Expand All @@ -27,19 +29,35 @@ If you use a terminal and you need to move between directories frequently, then

## Installation

1. Download and install [git](https://git-scm.com/download/win) (you'll need a git bash in order to use the app)
### Linux

1. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for linux (file linux-x64.zip)

2. Open the folder with unpacked files in the terminal and run the setup

```bash
sudo chmod +x setup.sh && ./setup.sh ./
```

2. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for your specific platform
3. Restart the terminal

_By now, only Windows is supported_
Done! Now you can run `nav -h` for a list of all available commands

3. Run the setup
### Windows

1. Download and install [git](https://git-scm.com/download/win) (you'll need a git bash in order to use the app)

2. Download and unpack the latest [release](https://github.com/VladBrok/navigatio/releases) for your specific architecture (win-x64.zip or win-x86.zip)

3. Open the folder with unpacked files in the git bash and run the setup

```bash
source release-setup.sh
./setup.sh ./
```

Now you can run `nav -h` for a list of all available commands
4. Restart the git bash

Done! Now you can run `nav -h` for a list of all available commands

## Usage

Expand Down
4 changes: 3 additions & 1 deletion scripts/dev-build.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dotnet build src/navigatio --no-restore && source scripts/setup.sh src/navigatio/bin/debug/net6.0/
#!/usr/bin/env bash

dotnet build src/navigatio --no-restore && scripts/setup.sh src/navigatio/bin/debug/net6.0/
6 changes: 3 additions & 3 deletions scripts/nav.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env
#!/usr/bin/env bash

ROOT=$1
OUTPUT_FILE=${ROOT}output.sh
OUTPUT_FILE=$2

${ROOT}navigatio.exe ${OUTPUT_FILE} ${@:2}
${ROOT}/Navigatio ${OUTPUT_FILE} ${@:3}

if test -f ${OUTPUT_FILE}; then
source ${OUTPUT_FILE}
Expand Down
3 changes: 0 additions & 3 deletions scripts/release-setup.sh

This file was deleted.

18 changes: 11 additions & 7 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env
#!/usr/bin/env bash

PROJECT_DIR=src/navigatio
BASE_DIR=${PROJECT_DIR}/bin/Release

rm -rf ${BASE_DIR}/x86 && \
dotnet publish $PROJECT_DIR -c Release -o ${BASE_DIR}/x86 -a x86 --sc true && \
powershell Compress-Archive -Path "'${BASE_DIR}/x86/*'" -DestinationPath 'windows-x86.zip' -Force
function release_for_os() {
rm -rf ${BASE_DIR}/$1 && \

rm -rf ${BASE_DIR}/x64 && \
dotnet publish $PROJECT_DIR -c Release -o ${BASE_DIR}/x64 -a x64 --sc true && \
powershell Compress-Archive -Path "'${BASE_DIR}/x64/*'" -DestinationPath 'windows-x64.zip' -Force
dotnet publish $PROJECT_DIR --configuration Release --output ${BASE_DIR}/$1 --runtime $1 --self-contained true && \

powershell Compress-Archive -Path "'${BASE_DIR}/$1/*'" -DestinationPath "$1.zip" -Force
}

release_for_os win-x86
release_for_os win-x64
release_for_os linux-x64
51 changes: 42 additions & 9 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
#!/usr/bin/env
#!/usr/bin/env bash

ROOT=/usr/local/bin/navigatio
EXE_PATH=$1
export ROOT=/usr/local/bin/navigatio
export EXE_PATH=$1

mkdir -p $ROOT
cp -r ${EXE_PATH}. $ROOT
chmod +x ${ROOT}/nav.sh
function create_dir() {
mkdir -p $ROOT
cp -r ${EXE_PATH}. $ROOT
}

echo "" >> ~/.bashrc
echo "alias nav='source ${ROOT}/nav.sh ${ROOT}/'" >> ~/.bashrc
source ~/.bashrc
function sudo_create_dir() {
sudo -E bash -c "$(declare -f create_dir); create_dir"
}

function set_permissions() {
sudo touch ${ROOT}/output.sh
sudo touch ${ROOT}/aliases.json
sudo touch ${ROOT}/history.json

sudo chmod a+x ${ROOT}/nav.sh
sudo chmod a+x ${ROOT}/Navigatio
sudo chmod a+wx ${ROOT}/output.sh
sudo chmod a+w ${ROOT}/settings.json
sudo chmod a+w ${ROOT}/aliases.json
sudo chmod a+w ${ROOT}/history.json
}

function create_alias() {
echo "" >> ~/.bashrc
echo "alias nav='source ${ROOT}/nav.sh ${ROOT} ${ROOT}/output.sh'" >> ~/.bashrc
}

unamestr=$(uname)
if [[ "$unamestr" == 'Linux' ]]
then
sudo_create_dir
set_permissions
else
create_dir
fi

create_alias

unset ROOT
unset EXE_PATH
2 changes: 1 addition & 1 deletion scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env
#!/usr/bin/env bash

rm -rf /usr/local/bin/navigatio
2 changes: 1 addition & 1 deletion settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"CommandHistoryLimit": 100,
"FavoriteEditor": "notepad"
"FavoriteEditor": null
}
54 changes: 42 additions & 12 deletions src/Navigatio/Commands/ChangeSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Navigatio.Storages;
using System.Runtime.InteropServices;

namespace Navigatio.Commands;

Expand All @@ -9,33 +10,46 @@ public class ChangeSettings : IExecutable, ICancellable

public ChangeSettings(Settings current, IStorage<Settings> storage)
{
OldSettings = current;
Settings = current;
_storage = storage;
}

public Settings OldSettings { get; set; }
public Settings Settings { get; set; }

public bool Execute(params string[] _)
{
Process? editor;
string editor = "";
try
{
var info = new ProcessStartInfo(OldSettings.FavoriteEditor ?? "", _storage.File)
{
Verb = "Edit"
};
editor = Process.Start(info) ?? throw new NullReferenceException();
editor = Settings.FavoriteEditor ?? GetDefaultEditor();
}
catch
catch (PlatformNotSupportedException)
{
Console.WriteLine(
$"Failed to open your favorite editor ({OldSettings.FavoriteEditor})."
$"Sorry, your OS is currently not supported. Please open file {_storage.File} and edit it manually."
);
return false;
}

if (Settings.FavoriteEditor is null)
{
Console.WriteLine($"Note: favorite editor is not specified. Falling back to {editor}.");
}

Process? editorInstance;
try
{
var info = new ProcessStartInfo(editor, _storage.File) { Verb = "Edit" };
editorInstance = Process.Start(info) ?? throw new NullReferenceException();
}
catch
{
Console.WriteLine($"Failed to open your favorite editor ({editor}).");
return false;
}

Console.WriteLine("Waiting for your editor to exit...");
editor?.WaitForExit();
editorInstance?.WaitForExit();
Console.WriteLine("Settings are changed.");
return true;
}
Expand All @@ -45,9 +59,25 @@ public void Cancel()
_storage.Load(
settings =>
{
OldSettings.ShallowCopyTo(settings);
Settings.ShallowCopyTo(settings);
Console.WriteLine("Settings are changed.");
}
);
}

private string GetDefaultEditor()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "vi";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "notepad";
}
else
{
throw new PlatformNotSupportedException();
}
}
}
1 change: 0 additions & 1 deletion src/Navigatio/Navigatio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<ItemGroup>
<None Include="../../settings.json" CopyToOutputDirectory="PreserveNewest" />
<None Include="../../scripts/nav.sh" CopyToOutputDirectory="PreserveNewest" />
<None Include="../../scripts/release-setup.sh" CopyToOutputDirectory="PreserveNewest" />
<None Include="../../scripts/setup.sh" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Expand Down

0 comments on commit 3a734b0

Please sign in to comment.