Skip to content

Commit

Permalink
📝 next-fouc-v13.md
Browse files Browse the repository at this point in the history
  • Loading branch information
elzup committed May 2, 2023
1 parent 90f6f8a commit fe0b62c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions content/blog/2023/2023-05-03___get-github-repo-id.md
@@ -0,0 +1,37 @@
---
title: GitHub のリポジトリ名やownerを取得するシェル
date: 2023-05-03 00:00:00
topics:
- GitHub
- git
- bash
type: tech
published: true
emoji: 🐚
---

git のディレクトリで remote に設定されている GitHub リポジトリの owner や repo 名を取得するシェルです。

## remote URL の取得

```sh
url=$(git config --get remote.origin.url)
echo $url
# git@github.com:elzup/kit-sh.git
```

## url から owner と repo をパースする

```sh
id=$(echo $url |sed -e 's/.*github.com.\(.*\).git/\1/')
# elzup/kit-sh

echo ${id#*/}
# kit-sh
echo ${id%/*}
# elzup
```

bash の変数展開でパターン照合演算子を使っています。
`echo ${id#*/}``id` の先頭から `/` までを削除します。
`echo ${id%/*}``id` の末尾から `/` までを削除します。

0 comments on commit fe0b62c

Please sign in to comment.