Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ lib/*
atcoder-cli-nodejs/*/makefile
atcoder-cli-nodejs/session.json
.local/share/
.local/bin/
erl_crash.dump
13 changes: 11 additions & 2 deletions lib/.support/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,22 @@ tf: $(TARGET) test/sample-1.in

SRC_FILE ?= $(SRC)

# 提出ページを開く処理は、実行可能な個人用 opener が配置されていればそちらに
# 委譲する。共有ファイルである本 makefile を編集せずに「開き方」を各自で
# 差し替えられるようにするための拡張点。未配置なら従来どおり $(OPEN) で開く。
SUBMIT_OPENER ?= $(HOME)/.local/bin/submit-opener

s: $(TARGET)
@test -f "$(SRC_FILE)" || { echo "$(SRC_FILE) が存在しません" >&2; exit 1; }
@payload=$$(base64 < "$(SRC_FILE)" | tr -d '\n\r'); printf '\033]52;c;%s\033\134' "$$payload"
@echo "$(SRC_FILE) をクリップボードにコピーしました"
@submit_url=$$(printf '%s\n' "$(TASK_URL)" | sed 's|/tasks/\(.*\)|/submit?taskScreenName=\1|'); \
$(OPEN) "$$submit_url"
@echo "提出ページを開きました。Ctrl+V (Cmd+V) でコードを貼り付けて提出してください"
if [ -x "$(SUBMIT_OPENER)" ]; then \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [MEDIUM] SUBMIT_OPENER のパスにスペースが含まれる場合の問題

$(HOME)/home/user name のようにスペースを含む環境では、[ -x "$(SUBMIT_OPENER)" ] の展開結果が [ -x /home/user name/.local/bin/submit-opener ] となり、シェルの単語分割によって引数が複数に分かれてテストが失敗します。また "$(SUBMIT_OPENER)" の二重引用符はMakeの展開後に付くため、Make変数展開時点ではクォートされていません。

より堅牢にするには、変数をシェル変数に一度代入してからクォートする方法が有効です:

	submit_url=$$(...); \
	opener="$(SUBMIT_OPENER)"; \
	if [ -x "$$opener" ]; then \
	  "$$opener" "$$submit_url" "$(SRC_FILE)"; \
	else \
	  $(OPEN) "$$submit_url"; \
	  echo "提出ページを開きました。..."; \
	fi

ただし、$(HOME) にスペースが含まれる環境は稀であるため、優先度はMEDIUMとします。

"$(SUBMIT_OPENER)" "$$submit_url" "$(SRC_FILE)"; \
else \
$(OPEN) "$$submit_url"; \
echo "提出ページを開きました。Ctrl+V (Cmd+V) でコードを貼り付けて提出してください"; \
fi

run: $(TARGET)
$(RUN_TEST)
Expand Down
Loading