{"action":"created","issue":{"url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/356","repository_url":"https://api.github.com/repos/KittyKatt/screenFetch","labels_url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/356/labels{/name}","comments_url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/356/comments","events_url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/356/events","html_url":"https://github.com/KittyKatt/screenFetch/issues/356","id":157273390,"number":356,"title":"Simple Caching Script","user":{"login":"cookrn","id":54619,"avatar_url":"https://avatars.githubusercontent.com/u/54619?v=3","gravatar_id":"","url":"https://api.github.com/users/cookrn","html_url":"https://github.com/cookrn","followers_url":"https://api.github.com/users/cookrn/followers","following_url":"https://api.github.com/users/cookrn/following{/other_user}","gists_url":"https://api.github.com/users/cookrn/gists{/gist_id}","starred_url":"https://api.github.com/users/cookrn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cookrn/subscriptions","organizations_url":"https://api.github.com/users/cookrn/orgs","repos_url":"https://api.github.com/users/cookrn/repos","events_url":"https://api.github.com/users/cookrn/events{/privacy}","received_events_url":"https://api.github.com/users/cookrn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-05-27T19:15:03Z","updated_at":"2016-09-03T22:46:47Z","closed_at":null,"body":"I like seeing `screenfetch` display when I open new terminals, but the wait was noticeable when opening multiple new terminal tabs or GNU Screen windows. So, I wrote a simple little ruby script to cache the output.\r\n\r\nhttps://gist.github.com/cookrn/885e45acb07f7cce51caaa70c34bab98\r\n\r\nHere's the source:\r\n\r\n```ruby\r\n#!/usr/bin/env ruby\r\n\r\nif fetched_file_blank? or fetched_file_expired?\r\n  fetch!\r\nend\r\n\r\nwrite_cached_screenfetch!\r\n\r\nBEGIN {\r\n  COMMAND = 'screenfetch'.freeze\r\n  EXPIRATION_TIMEOUT = 5 * 60 # 5 minutes\r\n  FETCHED_PATH = File.expand_path('~/.screenfetched').freeze\r\n  WRITE_MODE = 'w'.freeze\r\n\r\n  def fetch!\r\n    File.open(FETCHED_PATH, WRITE_MODE) do |f|\r\n      if f.flock(File::LOCK_EX|File::LOCK_NB)\r\n        f.write(`#{COMMAND}`)\r\n        f.flush\r\n      else\r\n        f.flock(File::LOCK_EX)\r\n      end\r\n\r\n      f.flock(File::LOCK_UN)\r\n    end\r\n  end\r\n\r\n  def fetched_file_blank?\r\n    !File.exist?(FETCHED_PATH)\r\n  end\r\n\r\n  def fetched_file_expired?\r\n    Time.now - File.mtime(FETCHED_PATH) > EXPIRATION_TIMEOUT\r\n  end\r\n\r\n  def write_cached_screenfetch!\r\n    File.open(FETCHED_PATH) do |f|\r\n      f.flock(File::LOCK_SH)\r\n      puts(f.read)\r\n    end\r\n  end\r\n}\r\n```\r\n\r\nI call the script `screenfetched` and place a call to it in my bash profile instead of `screenfetch` as I was using before. That way, when I open a bunch of new sessions at once either they're slow until the first one finishes, or they're all fast if it's already cached."},"comment":{"url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/comments/244574186","html_url":"https://github.com/KittyKatt/screenFetch/issues/356#issuecomment-244574186","issue_url":"https://api.github.com/repos/KittyKatt/screenFetch/issues/356","id":244574186,"user":{"login":"DmitryHetman","id":18743742,"avatar_url":"https://avatars.githubusercontent.com/u/18743742?v=3","gravatar_id":"","url":"https://api.github.com/users/DmitryHetman","html_url":"https://github.com/DmitryHetman","followers_url":"https://api.github.com/users/DmitryHetman/followers","following_url":"https://api.github.com/users/DmitryHetman/following{/other_user}","gists_url":"https://api.github.com/users/DmitryHetman/gists{/gist_id}","starred_url":"https://api.github.com/users/DmitryHetman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DmitryHetman/subscriptions","organizations_url":"https://api.github.com/users/DmitryHetman/orgs","repos_url":"https://api.github.com/users/DmitryHetman/repos","events_url":"https://api.github.com/users/DmitryHetman/events{/privacy}","received_events_url":"https://api.github.com/users/DmitryHetman/received_events","type":"User","site_admin":false},"created_at":"2016-09-03T22:46:47Z","updated_at":"2016-09-03T22:46:47Z","body":"Which lines exatly does it caches? \r\nYou need add option to screenfetch to update cache.\r\nhostname can be changed,\r\nKernel can be changed\r\nPackages can be changed,\r\nShell can be changed"}}
{"actor":{"display_login":"DmitryHetman"}}