kachick / times_kachick

`#times_kachick channel in chat` as a public repository. Personal Note and TODOs
https://github.com/kachick/times_kachick/issues?q=is%3Aissue+is%3Aclosed
6 stars 0 forks source link

2023-01-19 - ユーザーシェルを zsh とか fish じゃなく bash にしても今の zsh と同等の環境に出来たりしないかな #184

Closed kachick closed 1 year ago

kachick commented 2 years ago

ShellCheck とか shfmt みたいなエコシステムがどれもこれも zsh はサポートしていない。 rust 製の PowerShell みたいな https://github.com/nushell/nushell も出てきてて面白そうだけど、とりあえずなんかあんま考えたり新しい事覚えたりせず既存資産が動いてほしい。PowertShell も前覚えようとして結局あんまり身につかないままだったし・・・

そもそも現状あんま複雑なことはしてない。(と思ってたんだけど、実は裏で zsh さんがやってくれてただけ感・・・) prezto をほぼデフォルトで使ってたけど、 Sheldon とかに変えてみようかなと思ったところで、自分で zsh の機能を意識して使ったことがないんだから、bashと混在させるより操作環境自体 bash に統一出来た方が楽なんではと思った。 個人的に欠かせない感じの機能は何かなーと思ったら https://github.com/zsh-users/zsh-history-substring-search ぐらいだったんだけど、 https://www.gnu.org/software/bash/manual/html_node/Commands-For-History.html 見ると history-substring-search-forward とか history-substring-search-backward がある。ということは bash でも出来るのでは・・・?

プロンプトは pure がいい感じに落ち着いてて好きなんだけど、機能的には https://starship.rs/ja-jp/ でカバーできてそうだから見た目だけ弄れば似たような感じにできるのでは。

kachick commented 2 years ago

と思ったらいきなり fileglob で詰まった。そうなんだ、 ** って zsh で実装された機能だったの・・・ 今の bash なら shopt -s globstar とかで挙動カスタマイズ出来たけど、その辺に差分出てくると書くシェルスクリプトで常に意識する必要出てきそうでむしろ zsh との混在より混乱したりせんかな・・・

https://atmarkit.itmedia.co.jp/ait/articles/1912/26/news018.html https://makiuchi-d.github.io/2020/04/11/bash-zsh-globstar.ja.html https://qiita.com/anqooqie/items/a2b607fe984ec982fa21 https://github.com/scop/bash-completion https://hkoba.hatenablog.com/entry/2016/02/10/230206

https://ozuma.hatenablog.jp/entry/20141219/1418915137 とかまさにそのまんまの記事で面白かった。うーん・・・

kachick commented 2 years ago

GitHub Actions で使う時に -xe みたいな指定できないのかなと思ったけど起動時オプションにそれっぽいの無いような・・・

https://qiita.com/YusukeHosonuma/items/493ecc07eeefe5f718c1

❯ bash --help
GNU bash, version 5.1.16(1)-release-(x86_64-pc-linux-gnu)
Usage:  bash [GNU long option] [option] ...
        bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --pretty-print
        --rcfile
        --restricted
        --verbose
        --version
Shell options:
        -ilrsD or -c command or -O shopt_option         (invocation only)
        -abefhkmnptuvxBCHP or -o option
Type `bash -c "help set"' for more information about shell options.
Type `bash -c help' for more information about shell builtin commands.
Use the `bashbug' command to report bugs.

bash home page: <http://www.gnu.org/software/bash>
General help using GNU software: <http://www.gnu.org/gethelp/>
❯ bash -c 'help set' | less
set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
    Set or unset values of shell options and positional parameters.

    Change the value of shell attributes and positional parameters, or
    display the names and values of shell variables.

    Options:
      -a  Mark variables which are modified or created for export.
      -b  Notify of job termination immediately.
      -e  Exit immediately if a command exits with a non-zero status.
      -f  Disable file name generation (globbing).
      -h  Remember the location of commands as they are looked up.
      -k  All assignment arguments are placed in the environment for a
          command, not just those that precede the command name.
      -m  Job control is enabled.
      -n  Read commands but do not execute them.
      -o option-name
          Set the variable corresponding to option-name:
              allexport    same as -a
              braceexpand  same as -B
              emacs        use an emacs-style line editing interface
              errexit      same as -e
              errtrace     same as -E
              functrace    same as -T
              hashall      same as -h
              histexpand   same as -H
              history      enable command history
              ignoreeof    the shell will not exit upon reading EOF
              interactive-comments
                           allow comments to appear in interactive commands
              keyword      same as -k
              monitor      same as -m
              noclobber    same as -C
              noexec       same as -n
              noglob       same as -f
              nolog        currently accepted but ignored
              notify       same as -b
              nounset      same as -u
              onecmd       same as -t
              physical     same as -P
              pipefail     the return value of a pipeline is the status of
                           the last command to exit with a non-zero status,
                           or zero if no command exited with a non-zero status
              posix        change the behavior of bash where the default
                           operation differs from the Posix standard to
                           match the standard
              privileged   same as -p
              verbose      same as -v
              vi           use a vi-style line editing interface
              xtrace       same as -x
      -p  Turned on whenever the real and effective user ids do not match.
          Disables processing of the $ENV file and importing of shell
          functions.  Turning this option off causes the effective uid and
          gid to be set to the real uid and gid.
      -t  Exit after reading and executing one command.
      -u  Treat unset variables as an error when substituting.
      -v  Print shell input lines as they are read.
      -x  Print commands and their arguments as they are executed.
      -B  the shell will perform brace expansion
      -C  If set, disallow existing regular files to be overwritten
          by redirection of output.
      -E  If set, the ERR trap is inherited by shell functions.
      -H  Enable ! style history substitution.  This flag is on
          by default when the shell is interactive.
      -P  If set, do not resolve symbolic links when executing commands
          such as cd which change the current directory.
      -T  If set, the DEBUG and RETURN traps are inherited by shell functions.
      --  Assign any remaining arguments to the positional parameters.
          If there are no remaining arguments, the positional parameters
          are unset.
      -   Assign any remaining arguments to the positional parameters.
          The -x and -v options are turned off.

    Using + rather than - causes these flags to be turned off.  The
    flags can also be used upon invocation of the shell.  The current
    set of flags may be found in $-.  The remaining n ARGs are positional
    parameters and are assigned, in order, to $1, $2, .. $n.  If no
    ARGs are given, all shell variables are printed.

    Exit Status:
    Returns success unless an invalid option is given.
kachick commented 2 years ago

bash なら一々 zsh 入れないで良いし今ならどこでも最初から使えるやろと思ってたんだけど、そっか、Macが今はzsh標準なのか・・・それも理由がbashのGPL化に伴って古いバージョンしか入れてないからということらしく、そうすると最近のbashで増えた切り替えオプション系も付けられない。かと言って bash 自体の入れ替えして使う気にもあんまならない・・・というかバージョン古いbashを内部で使ってることに変わらないんちゃうんかMacOS X

最初あんま惹かれなかった nushell だけど、かなり直感的に使えた。オブジェクト渡しではあるんだろうけど、感覚としてはテーブルをパイプで渡す感じで sql 感がある。そしてコマンドがとても Ruby っぽく、ブロック付きの each まで合ってびっくり。Rubyならこのメソッド名があるのでは?みたいなの入力すると本当にあって大体そんな感じに動いたりするので習得コストは実は低そう。Cross Platform なのも良いかもなーと思ってログインシェルにもしたんだけど、履歴検索機能が中途半端に弱くて且つ fzf みたいな外部ツールと連携させられないのがちょっと辛いかも。 https://github.com/nushell/nushell/issues/1616

ログインシェルは zsh のままで、一部操作する時に nushell へ切り替えて使うみたいな感じが良いのかなー。そうすると最終的に 3shell 環境考慮することになるの億劫なんだけど。

Mac の時も brew で bash 入れ直す前提で考えてみようかなー。カオス

kachick commented 1 year ago

https://github.com/kachick/times_kachick/issues/204 で Nix を使いだした。便利なんだけど、 nix-shell で叩くと bash が上がる。互換性保つために仕方ないようで、この機会に再度 bash への移行を検討してみた

ということで今では・・・?と思ったんだけど、使ってて凄いストレスフルなのに気が付いた。 それが syntax highlight え、ここでつっかかんの?と思ったけど、けっこう大変な話らしく、まともに実現できてるのは https://github.com/akinomyoga/ble.sh ぐらいっぽく、しかしこれが大作感凄くて流石に抵抗が。

それだけとはいえその一点でかなり感触悪くなっちゃうので、一旦別の面倒さを許容する感じに zsh を使い続ける感じにした。 https://github.com/chisui/zsh-nix-shell というのもあるけど自分はとりあえず毎回 nix-shell --command 'zsh' を叩くことにしている。

kachick commented 1 year ago

dotfiles シェルスクリプト管理がキツくなってきて go に差し替えだしたので、先人の知恵がなんかあるかと https://github.com/pankona/install/ を見に行ったら シェルスクリプトの比率がやたら低い。 どう探しても https://github.com/pankona/install/blob/19e422f31d8d319cbc399d159111ca4bdf3acba1/mybashrc しか rc 系が見当たらないのでまさかと思いつつ本人に聞いてみると、

ということでカルチャーショックだった。

素に近い fish はカスタマイズ重ねた zsh より軽いので選んだけれど、偶にほぼ触ってない状態の bash 立ち上げると速さの次元の違いにビビるので、ちょっとうらやましくなってきた。