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

WM Integration: i3block #27

Closed
alx opened this issue Sep 11, 2016 · 2 comments
Closed

WM Integration: i3block #27

alx opened this issue Sep 11, 2016 · 2 comments

Comments

@alx
Copy link

alx commented Sep 11, 2016

Hi @mrichar1 ,

Thanks a lot for this tool, I had great time playing with it and it'll probably help my a lot in various pipelines in coming years.

Here is a quick gadget I made to integrate clipster into i3block, allowing me to quickly view if an element has been copied, and helping me merging the last 2 elements from the pasteboard (main usecase: merging a website url with a matching text description).

  • insert into $HOME/.i3blocks.conf
[clipster]                                                
command=$HOME/.config/i3/clipster                         
interval=1
  • insert into $HOME/.config/i3/clipster
#!/bin/bash

shortlength=30;
content=`clipster -o -n 2`;

if [ ${#content} -gt 0 ]; then

  isFirstLineRead=false;

  firstLine="";
  secondLine="";

  while read -r line; do
    if [ "$isFirstLineRead" = false ]; then
      isFirstLineRead=true;
      firstLine=$line;
    else
      secondLine=$line;
    fi
  done <<< "$content"

  case $BLOCK_BUTTON in
    1) echo "$secondLine $firstLine" | clipster ;;
  esac

  if [ ${#firstLine} -gt 30 ]; then
    firstLine="${firstLine:0:20}...${firstLine: -10}"
  fi

  if [ ${#secondLine} -gt 30 ]; then
    secondLine="${secondLine:0:7}..."
  fi

  echo "$secondLine | $firstLine"

else
  echo "#empty#"
fi
  • add executable flag on $HOME/.config/i3/clipster
chmod +x $HOME/.config/i3/clipster
  • restart i3wm: i3-msg restart

The bash script could probably be clearer, improvements and other ideas are welcomed. I'll test it for a week and propose it to https://github.com/acleverpun/i3-blocks-contrib next weekend.

Have a nice day,

Alex

@alx
Copy link
Author

alx commented Sep 12, 2016

Here is an updated version, where you can set the clipster element you want to fetch, using instance variable from i3block.

  • $HOME/.i3block.conf
 [clipster2]                                                                      
 command=$HOME/.config/i3/clipster                                                
 instance=2                                                                       
 interval=1                                                                       

 [clipster1]                                                                      
 command=$HOME/.config/i3/clipster                                                
 instance=1                                                                       
 interval=1 
  • $HOME/.config/i3/clipster
#!/bin/bash

content=`clipster -o -n $BLOCK_INSTANCE | tail -n1`;

if [ ${#content} -gt 0 ]; then

  case $BLOCK_BUTTON in
    1)
      previous=`clipster -o -n $(($BLOCK_INSTANCE + 1)) | tail -n1`;
      echo "$previous $content" |  tr -d '\n' | clipster
      ;;
  esac

  if [ ${#content} -gt 30 ]; then
    content="${content:0:20}...${content: -10}"
  fi

  echo "$content"

else
  echo "#empty#"
fi

The click on the block is now only merging the previous element (instance index) from clipster.

@mrichar1
Copy link
Owner

Thanks for this - this does look useful! I'll close this issue, but keep an eye on the i3blocks contrib repo 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants