Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add write_perm func and doc #340

Merged
merged 11 commits into from
Sep 29, 2018
13 changes: 13 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SPACESHIP_PROMPT_ORDER=(
time # Time stampts section
user # Username section
dir # Current directory section
write_perm # Write permission in current directory
host # Hostname section
git # Git section (git_branch + git_status)
hg # Mercurial section (hg_branch + hg_status)
Expand Down Expand Up @@ -137,6 +138,18 @@ Directory is always shown and truncated to the value of `SPACESHIP_DIR_TRUNC`. W
| `SPACESHIP_DIR_TRUNC_REPO` | `true` | While in `git` repo, show only root directory and folders inside it |
| `SPACESHIP_DIR_COLOR` | `cyan` | Color of directory section |

### Write permission (`write_perm`)

Display a padlock if current directory is write-protected or if current user has not rights to write into current folder.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
| `SPACESHIP_WRITE_PERM_SHOW` | `true` | Show section (`false` to hide) |
| `SPACESHIP_WRITE_PERM_PREFIX` | `` | Prefix before section |
| `SPACESHIP_WRITE_PERM_SUFFIX` | `·` | Suffix after section |
| `SPACESHIP_WRITE_PERM_COLOR` | `red` | Color of the icon |
| `SPACESHIP_WRITE_PERM_ICON` | `` | Icon displayed |
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this icon look like? In my terminal, that doesn't look like a padlock, but 🔒 does (link).

Also, I think this should be SYMBOL, not ICON (for consistency with the rest of spaceship).

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently the currently used icon is from FontAwesome and I didn't even notice this because I have FontAwesome installed, but I agree that the default icon should be from Unicode standard.

Copy link
Contributor

Choose a reason for hiding this comment

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

The lock symbol from Powerline font actually looks not bad too, since other sections use Powerline symbols already maybe it can be a default?

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I would still prefer default unicode symbols when suitable ones exist. Many users forget to install powerline fonts. Some things are fairly obvious (e.g.  master), but some things aren't so clear
(e.g. /etc  vs. /etc 🔒)

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed 👍

Copy link
Member

Choose a reason for hiding this comment

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

We already require powerline font, so why not? Powerline lock icon looks more native that Unicode one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Powerline lock icon looks more native that Unicode one.

I agree, but I think the argument was that it's you and me who installed Powerline fonts, but others might decided to not install it. So far it was mostly needed for git branch icon, and it is possible that many users decided that they are fine not installing Powerline font and seeing  master instead of  master. Such users will now start seeing /etc .

I'll let @nfischer continue, I'm fine with any icon as default 😛


### Git (`git`)

Git section is consists with `git_branch` and `git_status` subsections. It is shown only in Git repositories.
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [Username (user)](/docs/Options.md#username-user)
* [Hostname (host)](/docs/Options.md#hostname-host)
* [Directory (dir)](/docs/Options.md#directory-dir)
* [Write permission (write_perm)](/docs/Options.md#write-permission)
* [Git (git)](/docs/Options.md#git-git)
* [Git branch (git_branch)](/docs/Options.md#git-branch-gitbranch)
* [Git status (git_status)](/docs/Options.md#git-status-gitstatus)
Expand Down Expand Up @@ -56,4 +57,3 @@
* [spaceship::displaytime](/docs/API.md#spaceshipdisplaytime-seconds)
* [spaceship::union](/docs/API.md#spaceshipunion-arr1-arr2-)
* [Troubleshooting](/docs/Troubleshooting.md)

Copy link
Member

Choose a reason for hiding this comment

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

Do not remove the last empty line. You can use .editorconfig which is already present in our repo.

Copy link
Member

Choose a reason for hiding this comment

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

Reverted to original file.

32 changes: 32 additions & 0 deletions sections/write_perm.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Write permission
#
# Display a padlock if current directory is write-protected or
# if current user has not the rights to write.

# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------

SPACESHIP_WRITE_PERM_SHOW="${SPACESHIP_WRITE_PERM_SHOW=true}"
SPACESHIP_WRITE_PERM_PREFIX="${SPACESHIP_WRITE_PERM_PREFIX=""}"
SPACESHIP_WRITE_PERM_SUFFIX="${SPACESHIP_WRITE_PERM_SUFFIX=" "}"
SPACESHIP_WRITE_PERM_COLOR="${SPACESHIP_WRITE_PERM_COLOR=red}"
SPACESHIP_WRITE_PERM_ICON="${SPACESHIP_WRITE_PERM_ICON=""}"


# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------

spaceship_write_perm() {
[[ $SPACESHIP_WRITE_PERM_SHOW == false ]] && return

[[ -w . ]] && return

spaceship::section \
"$SPACESHIP_WRITE_PERM_COLOR" \
"$SPACESHIP_WRITE_PERM_PREFIX" \
"$SPACESHIP_WRITE_PERM_ICON" \
"$SPACESHIP_WRITE_PERM_SUFFIX"
}
1 change: 1 addition & 0 deletions spaceship.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if [ -z "$SPACESHIP_PROMPT_ORDER" ]; then
time # Time stampts section
user # Username section
dir # Current directory section
write_perm # Write permission in current directory
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't have to be a separate section, Can we combine this dir section ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this idea!

Copy link
Contributor

@maximbaz maximbaz Jan 21, 2018

Choose a reason for hiding this comment

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

Another reason why I think it would be nice to have this as part of the dir section is because I'd like to move the "lock sign" closer to the directory name:

image

It's not as important for lock symbol, but personally I think I'll be using *, as lock is too massive in my mind:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this ?

spaceship_dir() {
  [[ $SPACESHIP_DIR_SHOW == false ]] && return

  local dir

  # Threat repo root as a top-level directory or not
  if [[ $SPACESHIP_DIR_TRUNC_REPO == true ]] && spaceship::is_git; then
    local git_root=$(git rev-parse --show-toplevel)
    dir="$git_root:t${$(expr $(pwd) : "$git_root\(.*\)")}"
  else
    dir="%${SPACESHIP_DIR_TRUNC}~"
  fi

  spaceship::section \
    "$SPACESHIP_DIR_COLOR" \
    "$SPACESHIP_DIR_PREFIX" \
    "$dir" \
    "$SPACESHIP_DIR_SUFFIX"

  [[ $SPACESHIP_WRITE_PERM_SHOW == false ]] && return

  [[ -w . ]] && return

  spaceship::section \
    "$SPACESHIP_WRITE_PERM_COLOR" \
    "$SPACESHIP_WRITE_PERM_PREFIX" \
    "$SPACESHIP_WRITE_PERM_SYMBOL" \
    "$SPACESHIP_WRITE_PERM_SUFFIX"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Such approach won't allow moving PERM_SYMBOL closer to the directory name, but I can live without it, I think I'll be using Powerline's lock symbol and it looks better with a space anyway.

image

Wait for @salmanulfarzy to reply if this is what he had in mind code-wise though.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need all this options ? In my opinion, Only SPACESHIP_WRITE_PERM_COLOR and SPACESHIP_WRITE_PERM_SYMBOL are needed.

I would rather replace/append lock symbol to SPACESHIP_DIR_SUFFIX than making it a separate section. Altering SPACESHIP_DIR_PREFIX might not be visible if dir is first section, Which is common.

SPACESHIP_DIR_WRITE_LOCK_SYMBOL="${SPACESHIP_DIR_WRITE_LOCK_SYMBOL=" 🔒 "}"

# Before invoking the section
if [[ ! -w . ]]; then
  SPACESHIP_DIR_SUFFIX="${SPACESHIP_DIR_WRITE_LOCK_SYMBOL}"
fi

It doesn't allow to change colour of symbol, But I don't see myself changing colour of lock symbol. If needed we could make use of escape codes in assignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better if we can change color of lock, to make it more visible...

Copy link
Member

Choose a reason for hiding this comment

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

Now we have two options

  if [[ ! -w . ]]; then
    SPACESHIP_DIR_SUFFIX="%F{$SPACESHIP_DIR_LOCK_COLOR}$SPACESHIP_DIR_WRITE_LOCK_SYMBOL%f"
  fi

dir-write-lock

I'm open to both options. Suggestion ?


Is it just me or the lock symbol stays opaque ? Tried with iTerm and Terminal.

host # Hostname section
git # Git section (git_branch + git_status)
hg # Mercurial section (hg_branch + hg_status)
Expand Down