独自のプロンプト

バリエーションA

# [2021.08.29] 追加
#####################
# 独自のprompt
#####################

function smart_pwd {
    local pwdmaxlen=$(( $COLUMNS-35 ))
    local trunc_symbol=".."
    local dir=${PWD##*/}
    local tmp=""
    pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
    if [[ $PWD == $HOME* ]]; then
        SMART_PWD="~${PWD#${HOME}}"
    else
        SMART_PWD="$PWD"
    fi
    # set title
    printf "\033]0;%s\007" "${USER}@${HOSTNAME}: ${SMART_PWD}"

    SMART_PWD_TRUNC=""
    local pwdoffset=$(( ${#SMART_PWD} - pwdmaxlen ))
    if [ ${pwdoffset} -gt "0" ]
    then
        tmp=${SMART_PWD:$pwdoffset:$pwdmaxlen}
        tmp=${trunc_symbol}/${tmp#*/}
        if [ "${#tmp}" -lt "${#SMART_PWD}" ]; then
            SMART_PWD_TRUNC="${trunc_symbol}"
            SMART_PWD="${tmp:${#trunc_symbol}}"
        fi
    fi
}

source ~/.git-prompt.sh

PROMPT_COMMAND="smart_pwd"
PS1_SEC_1="\[\e[$[COLUMNS-19]C\]\[\033[30m\033[47m\D{%a %b %d %T}\r\033[0m\]"
PS1_SEC_2="\[\033[48;5;17m\033[38;5;117m\]\u"
PS1_SEC_3="\[\033[1;37;42m\]@ \[\033[1;37;42m\]\h \[\033[48;5;232m\033[38;5;201m\]"
PS1_SEC_5="\[\033[38;5;86m\] "
PS1_SEC_7="\[\033[0m\]\n\[\033[38;5;41m\]"
PS1_SEC_9="\[\033[38;5;208m\]\$ \[\033[0m\]"


PS1=${PS1_SEC_1}${PS1_SEC_3}'${SMART_PWD_TRUNC}'${PS1_SEC_5}'${SMART_PWD}'${PS1_SEC_7}'$(__git_ps1 "(%s)")'${PS1_SEC_9}


#####################
# shellの再起動
#####################

alias bashrl='exec $SHELL -l'



バリエーションB

#####################
# 独自のprompt
#####################

function smart_pwd {
    local pwdmaxlen=$(( $COLUMNS-35 ))
    local trunc_symbol=".."
    local dir=${PWD##*/}
    local tmp=""
    pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
    if [[ $PWD == $HOME* ]]; then
        SMART_PWD="~${PWD#${HOME}}"
    else
        SMART_PWD="$PWD"
    fi
    # set title
    printf "\033]0;%s\007" "${USER}@${HOSTNAME}: ${SMART_PWD}"

    SMART_PWD_TRUNC=""
    local pwdoffset=$(( ${#SMART_PWD} - pwdmaxlen ))
    if [ ${pwdoffset} -gt "0" ]
    then
        tmp=${SMART_PWD:$pwdoffset:$pwdmaxlen}
        tmp=${trunc_symbol}/${tmp#*/}
        if [ "${#tmp}" -lt "${#SMART_PWD}" ]; then
            SMART_PWD_TRUNC="${trunc_symbol}"
            SMART_PWD="${tmp:${#trunc_symbol}}"
        fi
    fi
}

# git-prompt.shの中に__git_ps1があるので、インクルードする
# ファイルパスは環境によって違う可能性あり。
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh をダウンロードでもよい
source ~/.git-prompt.sh

PROMPT_COMMAND="smart_pwd"
PS1_SEC_1="\[\e[$[COLUMNS-19]C\]\[\033[48;5;55m\033[38;5;220m\D{%a %b %d %T}"
PS1_SEC_2="\r\033[0m\]\[\033[48;5;17m\033[38;5;117m\]\u\[\033[38;5;114m\]"
PS1_SEC_3="@\[\033[38;5;117m\]\h \[\033[48;5;232m\033[38;5;201m\]"
# PS1_SEC_4=$SMART_PWD_TRUNC
PS1_SEC_5="\[\033[38;5;86m\]"
# PS1_SEC_6=$SMART_PWD
PS1_SEC_7="\[\033[0m\]\n\[\033[38;5;41m\]"
# PS1_SEC_8=$(__git_ps1 "(%s)")
PS1_SEC_9="\[\033[38;5;208m\]\$ \[\033[0m\]"


PS1=${PS1_SEC_1}${PS1_SEC_2}${PS1_SEC_3}'${SMART_PWD_TRUNC}'${PS1_SEC_5}'${SMART_PWD}'${PS1_SEC_7}'$(__git_ps1 "(%s)")'${PS1_SEC_9}


#####################
# shellの再起動
#####################

alias bashrl='exec $SHELL -l'

★ビルド 【tabler (管理画面ライブラリ)】

https://github.com/tabler/tabler

tabler-dev $ gs

On branch master
nothing to commit, working tree clean
$ npm install
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated rollup-plugin-babel@4.4.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel.

added 1452 packages, and audited 1453 packages in 1m

114 packages are looking for funding
  run `npm fund` for details

10 vulnerabilities (3 low, 7 moderate)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
$ npm run start

> @tabler/core@1.0.0-beta3 start
> gulp start

[20:47:17] Using gulpfile ~/Desktop/tabler-dev/gulpfile.js
[20:47:17] Starting 'start'...
[20:47:17] Starting 'clean'...
[20:47:17] Starting 'clean-dirs'...
[20:47:17] Finished 'clean-dirs' after 8.41 ms
[20:47:17] Starting 'clean-jekyll'...
bundler: command not found: jekyll
Install missing gem executables with `bundle install`
[20:47:18] 'clean-jekyll' errored after 867 ms
[20:47:18] Error: exited with error code: 127
    at ChildProcess.onexit (/Users/{user}/Desktop/tabler-dev/node_modules/end-of-stream/index.js:40:36)
    at ChildProcess.emit (node:events:394:28)
    at ChildProcess.emit (node:domain:532:15)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at Process.callbackTrampoline (node:internal/async_hooks:130:17)
[20:47:18] 'clean' errored after 877 ms
[20:47:18] 'start' errored after 879 ms
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Fetching public_suffix 4.0.6


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 
Installing public_suffix 4.0.6
Fetching addressable 2.8.0
Installing addressable 2.8.0
Using bundler 1.17.2
Fetching colorator 1.1.0
Installing colorator 1.1.0
Fetching concurrent-ruby 1.1.9
Installing concurrent-ruby 1.1.9
Fetching eventmachine 1.2.7
Installing eventmachine 1.2.7 with native extensions
Fetching http_parser.rb 0.6.0
Installing http_parser.rb 0.6.0 with native extensions
Fetching em-websocket 0.5.2
Installing em-websocket 0.5.2
Fetching ffi 1.15.3
Installing ffi 1.15.3 with native extensions
Fetching forwardable-extended 2.6.0
Installing forwardable-extended 2.6.0
Fetching htmlbeautifier 1.3.1
Installing htmlbeautifier 1.3.1
Fetching htmlcompressor 0.4.0
Installing htmlcompressor 0.4.0
Fetching i18n 1.8.10
Installing i18n 1.8.10
Fetching sassc 2.4.0
Installing sassc 2.4.0 with native extensions
Fetching jekyll-sass-converter 2.1.0
Installing jekyll-sass-converter 2.1.0
Fetching rb-fsevent 0.11.0
Installing rb-fsevent 0.11.0
Fetching rb-inotify 0.10.1
Installing rb-inotify 0.10.1
Fetching listen 3.6.0
Installing listen 3.6.0
Fetching jekyll-watch 2.2.1
Installing jekyll-watch 2.2.1
Fetching rexml 3.2.5
Installing rexml 3.2.5
Fetching kramdown 2.3.1
Installing kramdown 2.3.1
Fetching kramdown-parser-gfm 1.1.0
Installing kramdown-parser-gfm 1.1.0
Fetching liquid 4.0.3
Installing liquid 4.0.3
Fetching mercenary 0.4.0
Installing mercenary 0.4.0
Fetching pathutil 0.16.2
Installing pathutil 0.16.2
Fetching rouge 3.26.0
Installing rouge 3.26.0
Fetching safe_yaml 1.0.5
Installing safe_yaml 1.0.5
Fetching unicode-display_width 1.7.0
Installing unicode-display_width 1.7.0
Fetching terminal-table 2.0.0
Installing terminal-table 2.0.0
Fetching jekyll 4.2.0
Installing jekyll 4.2.0
Fetching jekyll-random 0.1
Installing jekyll-random 0.1
Fetching jekyll-redirect-from 0.16.0
Installing jekyll-redirect-from 0.16.0
Fetching jekyll-tidy 0.2.2
Installing jekyll-tidy 0.2.2
Fetching mini_i18n 0.8.0
Installing mini_i18n 0.8.0
Fetching jekyll-timeago 0.14.0
Installing jekyll-timeago 0.14.0
Bundle complete! 5 Gemfile dependencies, 35 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ npm run start

> @tabler/core@1.0.0-beta3 start
> gulp start

[21:14:08] Using gulpfile ~/Desktop/tabler-dev/gulpfile.js
[21:14:08] Starting 'start'...
[21:14:08] Starting 'clean'...
[21:14:08] Starting 'clean-dirs'...
[21:14:08] Finished 'clean-dirs' after 11 ms
[21:14:08] Starting 'clean-jekyll'...
Configuration file: /Users/{user}/Desktop/tabler-dev/_config.yml
           Cleaner: Nothing to do for tmp.
           Cleaner: Nothing to do for src/pages/.jekyll-metadata.
           Cleaner: Nothing to do for src/pages/.jekyll-cache.
           Cleaner: Nothing to do for .sass-cache.
[21:14:10] Finished 'clean-jekyll' after 1.74 s
[21:14:10] Finished 'clean' after 1.75 s
[21:14:10] Starting 'sass'...
[21:14:10] gulp-debug: src/scss/demo.scss
[21:14:10] gulp-debug: src/scss/tabler-flags.scss
[21:14:10] gulp-debug: src/scss/tabler-payments.scss
[21:14:10] gulp-debug: src/scss/tabler-vendors.scss
[21:14:10] gulp-debug: src/scss/tabler.scss
[21:14:10] gulp-debug: 5 items
[21:14:12] Finished 'sass' after 1.92 s
[21:14:12] Starting 'js'...
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
[21:14:14] Finished 'js' after 2.05 s
[21:14:14] Starting 'build-jekyll'...
Configuration file: /Users/{user}/Desktop/tabler-dev/_config.yml
            Source: /Users/{user}/Desktop/tabler-dev/src/pages
       Destination: /Users/{user}/Desktop/tabler-dev/.tmp
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 6.286 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
[21:14:21] Finished 'build-jekyll' after 7.06 s
[21:14:21] Starting 'watch-jekyll'...
[21:14:21] Starting 'watch'...
[21:14:21] Starting 'browser-sync'...
[21:14:21] Finished 'watch' after 18 ms
[Browsersync] Access URLs:
 ----------------------------------------
       Local: http://localhost:3000
    External: http://192.168.128.141:3000
 ----------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 ----------------------------------------
[Browsersync] Serving files from: ./.tmp
[Browsersync] Watching files...
Configuration file: /Users/{user}/Desktop/tabler-dev/_config.yml
            Source: /Users/{user}/Desktop/tabler-dev/src/pages
       Destination: /Users/{user}/Desktop/tabler-dev/.tmp
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 3.573 seconds.
 Auto-regeneration: enabled for 'src/pages'
[Browsersync] Reloading Browsers... (buffered 109 events)
^C
$ gs
On branch master
nothing to commit, working tree clean

★★(大分類E) 新しいMac Book Pro

JSONデータをパース、フィルタリングできるJSONパーサ「jq」コマンドを使用します。

qiita.com

Homebrewでjqのインストール

$ brew install jq

シンボリックリンクの生成

$ brew link jq

検索例

$ curl "http://geoapi.heartrails.com/api/json?method=searchByPostal&postal=1010047" | jq





EX

stedolan.github.io

qiita.com


Homebrewでwgetのインストール

$ brew install wget

noel-ingenieur.hateblo.jp



目次へ戻る

noel-ingenieur.hateblo.jp

★★(大分類D) 新しいMac Book Pro

大分類 D

D1) TypeScript

D2) Gulp

D3) Yarn

D4) npmとyarnのコマンド早見表

D5) nodenv状況確認

npm install -g typescript

tscにPATHを通す。

eco export PATH=$PATH: `npm bin -g`
$ tsc -v

Version 4.3.5


$npm ls -g typescript

/Users/[user]/.anyenv/envs/nodenv/versions/16.4.2/lib
└── typescript@4.3.5

D2) Gulp

$ npm install --global gulp

.bash_profile に追記しておく

$ echo 'export PATH=$PATH:./node_modules/.bin' >> ~/.bash_profile
$  gulp -v
CLI version: 2.3.0
Local version: Unknown

D3)

  • [失敗した方法]
    • Homebrew経由
  • [成功した方法]
    • npm経由で、npm install -g yarn

https://chaika.hatenablog.com/entry/2021/03/26/083000

yarn のインストール
global へのインストールで少しハマったのでメモ

$ npm install -g yarn


# nodenv rehash で global にある npm へのパスを通す必要があった
$ nodenv rehash

$ yarn --version
1.22.11

D4)

https://qiita.com/rubytomato@github/items/1696530bb9fd59aa28d8

D5) nodenvで状況確認

https://qiita.com/kolife/items/61cd75da5906a147fe7f

$ curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash

Checking for `nodenv' in PATH: multiple
  You seem to have multiple nodenv installs in the following locations.
  Please pick just one installation and remove the others.
  
  /Users/[user]/.anyenv/envs/nodenv/bin/nodenv
  /usr/local/bin/nodenv



Checking for nodenv shims in PATH: OK
Checking `nodenv install' support: multiple
  You seem to have multiple `nodenv-install' in the following locations.
  Please pick just one installation and remove the others.
  
  # nodenv経由
  /Users/[user]/.anyenv/envs/nodenv/plugins/node-build/bin/nodenv-install
  # Homebrew経由
  /usr/local/bin/nodenv-install


Counting installed Node versions: 2 versions
Auditing installed plugins: OK

余計な方を削除

$ rm -rf /usr/local/bin/nodenv
$ rm -rf /usr/local/bin/nodenv-install

以下の表示が出たらOK

$ curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash

Checking for `nodenv' in PATH: /Users/[user]/.anyenv/envs/nodenv/bin/nodenv

Checking for nodenv shims in PATH: OK

Checking `nodenv install' support: /Users/[user]/.anyenv/envs/nodenv/plugins/node-build/bin/nodenv-install (node-build 4.9.46)

Counting installed Node versions: 2 versions

Auditing installed plugins: OK

qiita.com



目次へ戻る

noel-ingenieur.hateblo.jp