Skip to content

Commit

Permalink
2022 Q1 (#121)
Browse files Browse the repository at this point in the history
Discussion:
- https://github.com/bevry/dorothy/discussions/118

Closes:
- #120
- #7

Most of the work done in:
- de2170e
  • Loading branch information
balupton authored Apr 10, 2022
1 parent b690886 commit 686a1ba
Show file tree
Hide file tree
Showing 338 changed files with 23,209 additions and 15,016 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autoformatter friendly flake8 config (all formatting rules disabled)
[flake8]
extend-ignore = E1, E2, E3, E501, W1, W2, W3, W5
23 changes: 23 additions & 0 deletions .github/workflows/dorothy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: dorothy
"on":
- push
- pull_request
jobs:
test:
strategy:
matrix:
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Configure"
shell: 'script -q -e -c "bash {0}"'
run: |
chmod +x ./commands/*
./commands/dorothy dev
- name: "Test"
shell: 'script -q -e -c "bash {0}"'
run: |
./commands/dorothy test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# generic
**/.DS_Store
.vscode/
basic.vim

# custom to dorothy
Expand Down
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=black
10 changes: 10 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
1 change: 1 addition & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*out
14 changes: 14 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0.1
cli:
version: 0.8.0-beta
lint:
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
6 changes: 3 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"eamodio.gitlens",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"foxundermoon.shell-format",
"hedinne.popping-and-locking-vscode",
"jeff-hykin.better-shellscript-syntax",
"sidneys1.gitconfig",
"skyapps.fish-vscode",
"streetsidesoftware.code-spell-checker",
"timonwong.shellcheck"
"timonwong.shellcheck",
"Trunk.io"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
"unwantedRecommendations": ["foxundermoon.shell-format"]
}
9 changes: 4 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"[shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
"editor.defaultFormatter": "Trunk.io"
},
"[plaintext,mdx]": {
"editor.folding": false,
Expand All @@ -18,9 +18,8 @@
"editor.inlineSuggest.enabled": true,
"editor.insertSpaces": false,
"editor.renderControlCharacters": true,
"editor.renderIndentGuides": true,
"editor.renderWhitespace": "all",
"editor.tabSize": 3,
"files.trimTrailingWhitespace": true,
"workbench.colorTheme": "Popping and Locking"
"editor.tabSize": 4,
"files.trimTrailingWhitespace": true
// "workbench.colorTheme": "Popping and Locking"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ The [`itunes-owners` command](https://github.com/bevry/dorothy/tree/master/comma

The [`ios-dev` command](https://github.com/bevry/dorothy/tree/master/commands/ios-dev) lets you easily open the iOS simulator from the terminal.

The [`alias-details`](https://github.com/bevry/dorothy/tree/master/commands/alias-details), [`aliases`](https://github.com/bevry/dorothy/tree/master/commands/aliases), [`aliases-to-symlink`](https://github.com/bevry/dorothy/tree/master/commands/aliases-to-symlink), [`alias-path`](https://github.com/bevry/dorothy/tree/master/commands/alias-path), [`alias-verify`](https://github.com/bevry/dorothy/tree/master/commands/alias-details) commands will help you convert MacOS aliases into symlinks.
The [`alias-helper`](https://github.com/bevry/dorothy/tree/master/commands/alias-helper) will help you manage your macOS aliases, and if desired, convert them into symlinks.

### Media

Expand Down
42 changes: 0 additions & 42 deletions commands/alias-details

This file was deleted.

217 changes: 217 additions & 0 deletions commands/alias-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#!/usr/bin/env bash
source "$DOROTHY/sources/strict.bash"

function alias-helper() (
# =====================================
# Arguments

function help {
cat <<-EOF >/dev/stderr
ABOUT:
Wrappers around macOS aliases to make things easier.
USAGE:
alias-helper <action>
ACTIONS:
new -- <alias-file-path> <target-file-path>
Makes a new macOS alias file at the <alias-file-path> pointing to the <target-file-path>.
symlink -- <alias-file-path>
Converts the macOS alias file with its UNIX symlink equivalent.
verify -- <alias-file-path>
Verify the path is a macOS alias file.
target -- <alias-file-path>
Output the target if the path is a macOS alias file.
info -- <alias-file-path>
Human friendly details about the macOS alias file.
EOF
if test "$#" -ne 0; then
echo-error "$@"
fi
return 22 # Invalid argument
}

# process
local item action='' args=()
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--')
args+=("$@")
shift $#
break
;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*)
if test -z "$action"; then
action="$item"
else
help "An unrecognised argument was provided: $item"
fi
;;
esac
done

# =====================================
# Actions

function alias_verify {
local path="$1"
silent-stderr osascript <<-EOF
tell application "Finder"
set theItem to (POSIX file "$path") as alias
if the kind of theItem is "alias" then
get the posix path of ((theItem) as text)
end if
end tell
EOF
}

function alias_target {
local path="$1"
silent-stderr osascript <<-EOF
tell application "Finder"
set theItem to (POSIX file "$path") as alias
if the kind of theItem is "alias" then
get the POSIX path of ((original item of theItem) as text)
end if
end tell
EOF
}

function alias_info {
local path="$1" src target

# verify
src="$(alias_verify "$path" || :)"
if test -z "$src"; then
{
echo-style \
--bold+red="$path" \
$'\t' \
$'\t' --error='← not an alias'
return 22 # EINVAL Invalid argument
} >/dev/stderr
fi

# target
target="$(aliastarget "$path" || :)"
if test -z "$target"; then
{
stderr echo-style \
--bold="$src" \
$'\t' \
$'\t' --error='← target broken'
return 9 # EBADF Bad file descriptor
} >/dev/stderr
fi
if test ! -e "$target"; then
{
stderr echo-style \
--bold="$src" \
--nocolor=$'\t' --color+dim=$'\t\t' --bold+red="$target" \
$'\t' --error='← target missing'
return 2 # ENOENT No such file or directory
} >/dev/stderr
fi

# success
echo-style \
--bold="$src" \
--nocolor=$'\t' --color+dim=$'\t\t' --bold+green="$target"
}

function alias_new {
local path="$1" target="$2" type target_absolute path_absolute path_directory path_filename
target_absolute="$(fs-absolute "$target")"
path_absolute="$(fs-absolute "$path")"
path_directory="$(dirname "$path_absolute")"
path_filename="$(basename "$path_absolute")"

# act
if test -d "$target_absolute"; then
type="folder"
elif test -f "$target_absolute"; then
type="file"
else
{
echo-style --error='Invalid path or unsupported type:' ' ' --code="$path"
return 22 # EINVAL Invalid argument
} >/dev/stderr
fi

if test -f "$path_absolute"; then
fs-rm "$path_absolute"
fi

osascript <<-EOF
tell application "Finder"
make new alias to ${type} (posix file "$target_absolute") at (posix file "$path_directory")
set name of result to "$path_filename"
end tell
EOF

# make the alias's permissions the same as the target's
chmod "$(stat -f '%p' "$target_absolute")" "$path_absolute"
#chmod --reference="$targetPath" "$path_absolute"
}

function alias_symlink {
local path="$1" src target

# verify alias
src="$(alias_verify "$path" || :)"
if test -z "$src"; then
{
echo-style --bold+red="$path" ' ' --error='<- not an alias'
return 22 # EINVAL Invalid argument
} >/dev/stderr
fi

# verify target
target="$(alias_target "$path" || :)"
if test -z "$target"; then
{
echo-style --bold="$src" --dim='' --bold+red="$target" ' ' --error='← target broken'
return 9 # EBADF Bad file descriptor
} >/dev/stderr
fi
if test ! -e "$target"; then
{
echo-style --bold="$src" --dim='' --bold+red="$target" ' ' --error='← target missing'
return 2 # ENOENT No such file or directory
} >/dev/stderr
fi

# convert
if test -f "$target"; then
ln -nfs "$target" "$src"
echo "converted $path -> $target"
elif test -d "$target"; then
ln -nfs "$target" "$src"
echo "converted $path -> $target"
fi
}

# =====================================
# Act

if test "$(type -t "alias_$action")" = 'function'; then
"alias_$action" "${args[@]}"
return "$?"
else
echo-style --error="Action [$action] not yet implemented." >/dev/stderr
return 78 # Function not implemented
fi
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
alias-helper "$@"
fi
Loading

0 comments on commit 686a1ba

Please sign in to comment.